-
Notifications
You must be signed in to change notification settings - Fork 156
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
add caching, add tests #175
Conversation
Edit above, as i messed up the load_test before: From 30.857404708862305s to convert from dict to 16.02430510520935s to convert from dict |
You could try using https://deepdiff.readthedocs.io/en/latest/deephash.html to get object based hashes in to_dict, but I am not sure about introducing the dependency and if it improves the speed |
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.
Hey @Germandrummer92 thanks for implementing this optimization. 2x
speedup is great. Performance is definitely on the radar, as more people rely this library. I'll need to deep dive into it myself, but I have broad guesses at where other bottlenecks might be.
Also just want to say thank you to both you and @RunOrVeith for your contributions.
|
id should work for caching as the three functions in questions always will receive a class as an argument which will have same identity always. Tests are passing and I added some too.
Load test with cache_size=1:
After introducing caching:
So about a 2x speedup when converting from dict.
I did write a load_test and profiled it to get to those results. There is great improvement but as you can see with the graph the performance is still quite bad for encoding to the dict. I was trying to somehow improve performance of the as_dict as well but didn't find a good solution. A cache wouldn't really work there as the hashing itself would mean you need to do json.dumps or something to have a consistent hash, which I think (i didn't try) would not improve performance. Find the screenshot of the callgraph attached. If you have some other ideas to fix it that would be great!
profile results after caching:
@RunOrVeith