GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@AlexWaygood AlexWaygood commented Dec 4, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Performance of typing._ProtocolMeta._get_protocol_attrs and isinstance #74690

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
@AlexWaygood
pythongh-74690: Optimise isinstance() and issubclass() calls agai…
ec4051a
…nst runtime-checkable protocols by avoiding costly `super()` calls
@AlexWaygood AlexWaygood added the performance Performance or resource usage label Dec 4, 2023
@AlexWaygood
AlexWaygood requested a review from carljm December 4, 2023 14:17
@AlexWaygood
AlexWaygood requested a review from JelleZijlstra as a code owner December 4, 2023 14:17
@bedevere-app bedevere-app Bot added the awaiting core review label Dec 4, 2023
@bedevere-app bedevere-app Bot mentioned this pull request Dec 4, 2023
Performance of typing._ProtocolMeta._get_protocol_attrs and isinstance #74690
Closed
AlexWaygood added 2 commits December 4, 2023 14:18
@AlexWaygood
fix NEWS
ff333fd
@AlexWaygood
actually fix NEWS
a7d76f6
@AlexWaygood

AlexWaygood commented Dec 4, 2023

Copy link
Copy Markdown
Member Author

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
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@AlexWaygood AlexWaygood added the topic-typing label Dec 4, 2023
JelleZijlstra
JelleZijlstra approved these changes Dec 4, 2023
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Dec 4, 2023
carljm
carljm approved these changes Dec 4, 2023
View reviewed changes
@AlexWaygood
AlexWaygood merged commit c718ab9 into python:main Dec 4, 2023
@AlexWaygood
AlexWaygood deleted the protocol-costly-super-calls branch December 4, 2023 15:41
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 4, 2023
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
@AlexWaygood @aisk
pythongh-74690: Optimise isinstance() and issubclass() calls agai…
78c8faf
…nst runtime-checkable protocols by avoiding costly `super()` calls (python#112708)
@namka279

This comment was marked as spam.

Sign in to view
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
@AlexWaygood @Glyphack
pythongh-74690: Optimise isinstance() and issubclass() calls agai…
cb075b6
…nst runtime-checkable protocols by avoiding costly `super()` calls (python#112708)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@carljm carljm carljm approved these changes
@JelleZijlstra JelleZijlstra JelleZijlstra approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

performance Performance or resource usage topic-typing

Projects

None yet

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.

4 participants

@AlexWaygood @namka279 @carljm @JelleZijlstra
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.