Skip to content

Add a benchmark for runtime-checkable protocols #280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 27, 2023

Conversation

AlexWaygood
Copy link
Member

We had a longstanding issue open at CPython complaining that the performance of isinstance() checks against runtime-checkable protocols was a serious bottleneck for their programme. The performance of these isinstance() checks has been significantly improved for 3.12 compared to 3.11, but there's currently no code (to my knowledge) in pyperformance that significantly exercises isinstance() checks against runtime-checkable protocols.

Work towards #105.

Copy link
Contributor

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth having more than five. I just grepped and I found a runtime_checkable Protocol in a codebase at work with twenty one methods.....

@AlexWaygood
Copy link
Member Author

AlexWaygood commented Apr 25, 2023

Might be worth having more than five. I just grepped and I found a runtime_checkable Protocol in a codebase at work with twenty one methods.....

I did a fair amount of searching through grep.app while writing this benchmark to see what a typical runtime-checkable protocol is in the wild. The majority of runtime-checkable protocols in the wild appear to have 5 members or fewer. However, there are a few codebases that make heavy use of runtime-checkable protocols, and they often have "monster protocols" like the one you describe, which may have truly awful performance (and will probably have worse performance in 3.12 than they did in 3.11). One example of a codebase making heavy use of runtime-checkable protocols: https://github.com/feeluown/FeelUOwn/blob/master/feeluown/library/model_protocol.py.

So, I'm not sure what the best thing to do here is!

Copy link
Member

@brandtbucher brandtbucher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the time to do this, and for the helpful comment! I have a couple of questions/suggestions:

@AlexWaygood
Copy link
Member Author

Thanks for taking the time to do this, and for the helpful comment! I have a couple of questions/suggestions:

Thanks for the review! I think I addressed all the comments.

@AlexWaygood AlexWaygood merged commit 58330d1 into python:main Apr 27, 2023
@AlexWaygood AlexWaygood deleted the runtime-protocols branch April 27, 2023 02:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants