-
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
[ENG-3867] Garden Variety Pickle #4054
Conversation
c26714f
to
c466e2d
Compare
Removed the |
elif fp is not None and data is None: | ||
(substate_schema, state) = pickle.load(fp) | ||
else: | ||
raise ValueError("Only one of `data` or `fp` must be provided") |
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.
This else
will also trigger if both data and fp are None
.
Maybe need to adjust the message for that case?
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.
If neither are provided, then that's still an error. We need exactly one.
* Use regular `pickle` module from stdlib * Avoid recreating the rx.State tree for every `get_state` * Remove dill dependency * relock deps
Avoid
dill
Now that our states are simpler, we can pickle them using the built in c-implementation which is much faster.
Update
__module__
forComponentState
When we create component state substates, cache these generated classes on
reflex.state
so that the pickler can find them.Reduce state instantiations
The
StateManagerDisk
was creating a new state tree for everyget_state
call, which is a very expensive operation. Instead pull the root state from theself.states
cache if it's there.Simplify loading logic to make it clear that we only populate states on initial load where a client token is not saved in memory.Optimize output by only serializing states whereMoved to a different PR_get_was_touched()
returnsTrue
Bonus
Redis now throws away state when the schema changes, allowing for smoother app updates.
Profile
This profiles 4000 operations against the state. The operation causes the state to grow linearly in size.
async_timeit.py
Before (0.6.1)
After