GeezerVison is showing github.com — gh-74690: Optimise `isinstance()` and `issubclass()` calls against runtime-checkable protocols by avoiding costly `super()` calls by AlexWaygood · Pull Request #112708 · python/cpython
Conversation
AlexWaygood
commented
Dec 4, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Before:
>python -m timeit -s "from typing import SupportsIndex" "isinstance(0, SupportsIndex)"
Running PGUpdate|x64 interpreter...
1000000 loops, best of 5: 379 nsec per loop
>python -m timeit -s "from typing import SupportsIndex" "issubclass(int, SupportsIndex)"
Running PGUpdate|x64 interpreter...
500000 loops, best of 5: 592 nsec per loop
After:
>python -m timeit -s "from typing import SupportsIndex" "isinstance(0, SupportsIndex)"
Running PGUpdate|x64 interpreter...
1000000 loops, best of 5: 298 nsec per loop
>python -m timeit -s "from typing import SupportsIndex" "issubclass(int, SupportsIndex)"
Running PGUpdate|x64 interpreter...
500000 loops, best of 5: 523 nsec per loop
Timings done using a fresh PGO-optimised build on Windows with the main branch.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
bdraco reacted with hooray emoji
bdraco reacted with rocket emoji
All reactions
-
🎉
1 reaction
-
🚀
1 reaction
…nst runtime-checkable protocols by avoiding costly `super()` calls
|
For comparison, here's the timings against "normal" classes... we're still some way off 🙃 A lot closer than we were in 3.11, though.
>python -m timeit "isinstance(0, int)"
Running PGUpdate|x64 interpreter...
10000000 loops, best of 5: 27.4 nsec per loop
>python -m timeit "issubclass(str, int)"
Running PGUpdate|x64 interpreter...
10000000 loops, best of 5: 34.6 nsec per loop
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
aisk
pushed a commit
to aisk/cpython
that referenced
this pull request
Feb 11, 2024
…nst runtime-checkable protocols by avoiding costly `super()` calls (python#112708)
This comment was marked as spam.
Glyphack
pushed a commit
to Glyphack/cpython
that referenced
this pull request
Sep 2, 2024
…nst runtime-checkable protocols by avoiding costly `super()` calls (python#112708)
Reviewers
carljm
carljm approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|