-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-93714 Create fast version of match_keys for exact dict #93752
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
base: main
Are you sure you want to change the base?
Conversation
When the type is an exact dict, there's a real speed-up to be gained by skipping the call to "get" and using PyDict_GetItemWithError instead.
Do you have any benchmark results to prove whether this is worth it? |
I'd made a set of microbenchmarks for pattern matching. This change obviously only affects the first test subject (the dict). I've also included the second subject (an inexact dict) below for comparison.
It's about a 20% speed up here. If I increase the number of keys to be tested so that the subject is So the benefit is probably "real, but not huge". (I should add: I'm just compiling Python with |
With With this change
and without
So a fairly similar level of speed-up. |
I think this is heading in the wrong direction. |
I agree at least in principle - I known @brandtbucher said he'd done some work on that. I was mainly proposing this PR as a fairly simple short-term improvement. But I'd ultimately expect it to be replaced with bytecode. Please do reject it if you don't think the extra code is worth the improvement though. |
I won't close this just yet. |
When the type is an exact dict, there's a real speed-up to be gained by skipping the call to "get" and using PyDict_GetItemWithError instead. The implementation is just a slightly modified copy of the existing
match_keys
function.