-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reassign state Var when fields on a Base instance change #1748
Conversation
Yikes, this appears to approximately double the time taken by |
So I was thinking about this one a bit more... and instead of doing a full re-assignment (and reinitialization, etc) for these mutable types, we probably should just mark them dirty in the state. Essentially, we will add some code to Then With this approach, we won't need specialty collection objects and we won't need slow up-front depth first traversals. We can just mark the fields appropriately at runtime when they are accessed/modified. |
Use wrapt.ObjectProxy to provide generic nested change tracking within mutable structures.
Fix #1675 properly
ea49999
to
5ad6c01
Compare
5f337a0
to
582031b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, this solution ended up very clean :)
Refactor mutable type handling in State classes:
MutableProxy
object that wrapslist
,dict
,set
, andBase
-derived objects coming from the State.__magic_attrs__
are accessed on wrapped objects, and they are callable, mark the associated var field in the state as dirty.MutableProxy
associated with the original state and field_name.MutableProxy
back to the state, actually assign the wrapped object.This approach does not incur as much runtime overhead as the current implementation, since it does not create copies of objects just for state tracking and does not create copies of objects when assigning back to the state. Instead it just wraps the original mutable object.
Fixes #1675