Please sign in to comment.
Further encapsulate dirty checking on `Attribute`
We can skip the allocation of a full `AttributeSet` by changing the semantics of how we structure things. Instead of comparing two separate `AttributeSet` objects, and `Attribute` is now a singly linked list of every change that has happened to it. Since the attribute objects are immutable, to apply the changes we simply need to copy the head of the list. It's worth noting that this causes one subtle change in the behavior of AR. When a record is saved successfully, the `before_type_cast` version of everything will be what was sent to the database. I honestly think these semantics make more sense, as we could have just as easily had the DB do `RETURNING *` and updated the record with those if we had things like timestamps implemented at the DB layer. This brings our performance closer to 4.2, but we're still not quite there.
- Loading branch information...
Showing with 99 additions and 51 deletions.
- +45 −9 activerecord/lib/active_record/attribute.rb
- +2 −11 activerecord/lib/active_record/attribute/user_provided_default.rb
- +7 −4 activerecord/lib/active_record/attribute_methods/dirty.rb
- +7 −23 activerecord/lib/active_record/attribute_mutation_tracker.rb
- +0 −3 activerecord/test/cases/attribute_methods_test.rb
- +38 −1 activerecord/test/cases/attribute_test.rb