-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
ChainMap.__contains__ and .get performance improvement. #118932
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
Comments
I'm curious: how long does |
621 ns |
The change to The |
Makes sense, can't think of any way to keep that and not to iterate twice. At least updating Should I issue PR or leave it to you? |
How much slower is this? https://stackoverflow.com/a/44803103 any(True for m in self.maps if key in m) |
Slightly faster than the original:
|
... but slower than an actual for loop. |
786 ns & 500 ns |
Looks like a complicated version of:
|
Which is the best I have seen without loop: |
On slower systems, there is a noticable stall right after startup when all the discoveries hit if there are a lot of discoveries. While we have imporved this by avoding imports in the event loop, this is still apparent on slower systems. The any expressions kept coming up in the profile, but I had skipped over them, as I was thinking they could not be optimized. After reading python/cpython#118932, I realized its the any expressions themselves that perform poorly. This change unpacks the hot any expressions with the same solution as python/cpython#118946
Uh oh!
There was an error while loading. Please reload this page.
Feature or enhancement
Proposal:
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/collections-chainmap-get-performance/41925
Linked PRs
The text was updated successfully, but these errors were encountered: