Conversation
Documentation build overview
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If a match class pattern only contains keywords, it's not necessary to construct a temporary tuple with all the results from the
PyObject_GetOptionalAttrcalls before unpacking it again. Evaluating the keywords directly can provide a significant performance improvement, especially for patterns with just a few keywords (< 3) on the order of 20-30%. For 5 keywords it's closer to 10%.Adding a dedicated opcode
MATCH_CLASS_GET_OPT_ATTRalso unlocks the ability for further improvements through specialization later on, similarly toLOAD_ATTR. Testing with specialization disabled suggests that it might even be possible to get as fast or slightly fast than comparable if statements, even for a larger number of keywords.--
This PR does change the execution order slightly. Whereas currently a missing attribute on an instance would fail the pattern immediately before any sub-patterns are evaluated, with the change here each attribute and pattern will be evaluated together one after another. In practice this is highly unlikely to change results though.
Arguably the "new" behavior is the expected one based on the docs:
Though it should be noted that PEP 634 explicitly called out that part as undefined behavior a user should not rely on:
--
Micro benchmark (only keywords)