-
-
Notifications
You must be signed in to change notification settings - Fork 29.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
Optimize some set operations in dictkeys object #82794
Comments
-, |, and ^ of dictkeys are implemented as: PyObject *result = PySet_New(self);
// Call set.difference_update, set.update, set.symmetric_difference_update with other. PySet_New(iterable) has optimized step for iterable is dict. We can pass dict instead of dictkey object to PySet_New. $ ./python -m pyperf timeit -o patched.json -s 'k = dict.fromkeys("abcdefghijklmnopqrstuvwxyz").keys(); s={1,2,3}' -- 'k | {1,2,3}'
$ ./python -m pyperf compare_to master.json patched.json
Mean +- std dev: [master] 778 ns +- 17 ns -> [patched] 550 ns +- 24 ns: 1.42x faster (-29%) |
How does it work with dict subclasses? |
PySet_New(iterable) uses fast path only when So there is no change for dict subclasses. |
But what if a dict subclass overrides __iter__? You can get different result if set(d) != set(d.keys()). |
Consider testing PyDict_CheckExact. |
done. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: