gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns#139080
gh-138912: Add dedicated opcodes for MatchClass without positional sub-patterns#139080cdce8p wants to merge 19 commits into
Conversation
|
@cdce8p Could you please resolve conflicts? |
|
I believe this needs a what's new entry too. |
Maybe, but I think we should wait until both PRs are merged before adding a combined one. |
|
the earlier PR was merged, this could use an update. |
|
I extracted the |
3a6dcdb to
055b019
Compare
Documentation build overview
239 files changed ·
|
|
@cdce8p You don't need to merge This PR is in draft mode — are there any changes you still need to make before it's ready for core-dev review? |
Sorry for that. I merged main to get #148826 into the branch. It fixed an issue that prevented performance comparisons with specializations disabled.
Not technically. A while ago I opened #144820 which is essentially the first part of the changes here, just because I thought it might be easier to review. Unfortunately there hasn't been any movement on that since February. The decision seems to be hung on whether it is worth it to introduce a new opcode for the speedup. If you have some time, I'd appreciate another perspective on it. |
|
@eendebakpt Could you please take a look? |
This PR complements and extends the work done in #138915.
In a microbenchmark for bare class matches, the match statement is now even slightly faster than the comparable if statement. With keyword only patterns, the performance is much improved as it's no longer necessary to construct intermediary tuples so that's now only
~20%slower compared to theifequivalent. (Previously it was closer to~220%).Further improvements can likely be archived if
MATCH_CLASS_GET_OPT_ATTRis specialized in a similar manner toLOAD_ATTR. With the specialization for (just)LOAD_ATTRdisabled, thematchstatement equivalent is again slightly faster than the correspondingifclause.__
Micro benchmarks with all specializations enabled.
Micro benchmark (bare class pattern)
Micro benchmark (One keyword attribute)
📚 Documentation preview 📚: https://cpython-previews--139080.org.readthedocs.build/