mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
d29d459897
Currently `type.serialize` and `connection.{quote|type_cast}` for a time
object always does `time.getutc` call regardless of whether it is
already utc time object or not, that duplicated proccess
(`connection.type_cast(type.serialize(time))`) allocates extra/useless
time objects for each type casting.
This avoids that redundant `time.getutc` call if it is already utc time
object. In the case of a model has timestamps (`created_at` and
`updated_at`), it avoids 6,000 time objects allocation for 1,000 times
`model.save`.
```ruby
ObjectSpace::AllocationTracer.setup(%i{path line type})
pp ObjectSpace::AllocationTracer.trace {
1_000.times { User.create }
}.select { |k, _| k[0].end_with?("quoting.rb", "time_value.rb") }
```
Before (
|
||
---|---|---|
.. | ||
attribute | ||
attribute_set | ||
locale | ||
serializers | ||
type | ||
validations | ||
attribute.rb | ||
attribute_assignment.rb | ||
attribute_methods.rb | ||
attribute_mutation_tracker.rb | ||
attribute_set.rb | ||
attributes.rb | ||
callbacks.rb | ||
conversion.rb | ||
dirty.rb | ||
error.rb | ||
errors.rb | ||
forbidden_attributes_protection.rb | ||
gem_version.rb | ||
lint.rb | ||
model.rb | ||
naming.rb | ||
nested_error.rb | ||
railtie.rb | ||
secure_password.rb | ||
serialization.rb | ||
translation.rb | ||
type.rb | ||
validations.rb | ||
validator.rb | ||
version.rb |