gh-93714 Create fast version of match_keys for exact dict#93752
gh-93714 Create fast version of match_keys for exact dict#93752da-woods wants to merge 2 commits into
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. |
|
This PR is stale because it has been open for 30 days with no activity. |
There PR has been inactive for almost 3 years now, so maybe time to consider closing or picking up again. I explored a bit, here is a summary:
we can optimize to This requires a new tier1 opcode (the @markshannon @da-woods Any opinion on which way to go, and on whether this is worth the changes? |
|
@eendebakpt It sounds like you have up-to-date rebased versions of this + some other worthwhile optimizations. So even if we pick this up we should probably do it from your branch and close this one. I don't have a view on My personal view is the same as it was 3 years ago - that there are some fairly cheap optimizations here so it's worth doing something. But I'm not sure how much weight that opinion has. |
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_keysfunction.