-
Notifications
You must be signed in to change notification settings - Fork 206
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
unpickling very slow #203
Comments
One option (based on my limited Python experience) would be to switch to using setstate and getstate, and then set up the special methods in setstate? |
The update method has a fast path for when it’s initially empty. Please provide a simple benchmark to reproduce the issue. |
Here is a simple benchmark (I put a class in just to check if classes aren't always slow). The results are get are: 1.4263453999956255 0.07709820000309264 0.10215669999888632 So it is 20 times slower to unpickle a SortedSet than a set, and 14 times slow to unpickle a set with a single member. However, that might be considered a reasonable overhead -- in my case it is annoying as I'm using pickle to store a very large datastructure, and my program is "unpickle data structure, do some AI with it, close program". Code:
|
Hi, Thanks a lot for this project! I face a similar issue when loading a pickled Are you open to a PR? |
I can’t promise it’ll be merged but I’m certainly happy to review a solution. |
Hi,
I have some code where unpickling SortedLists and SortedSets takes a significant amount of the runtime of my program (I have a lot of them!)
The problem is, I think, that as
__reduce__
just says thatset
andkey
should be passed toinit
, then the iterable values then get fed intoself._update
one at a time.Would it be possible to speed things up, as the iterable is already known to be sorted? I wasn't sure of the best way to do this, one option would be to add a constructor method
issorted
, but then that might get used by other people (and maybe incorrectly), and you might not want that?The text was updated successfully, but these errors were encountered: