Skip to content
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

Add faster versions of various runtime-checkable protocols #146

Merged
merged 4 commits into from
Apr 26, 2023

Conversation

AlexWaygood
Copy link
Member

This is one way of resolving the disagreement in #143. The other way would be to just revert #141. No strong opinion either way :)

@AlexWaygood
Copy link
Member Author

(If this PR is accepted, I'll update #143 to talk about the new additions to typing_extensions in the README.)

@srittau
Copy link
Collaborator

srittau commented Apr 18, 2023

Looking back at #141, I'm not sure how relevant the speedups are and whether it's worth complicating typing_extensions for it. But I don't feel strongly about either. So, -0 and +0 on reverting #141.

@AlexWaygood
Copy link
Member Author

I'm not sure how relevant the speedups are

I'd argue the speedups are quite relevant. The optimisations we've introduced into Python 3.12 were designed to address a longstanding user report where _ProtocolMeta.__instancecheck__ was revealed to be a significant bottleneck in their code: python/cpython#74690. Elsewhere, the slowness of _ProtocolMeta.__instancecheck__ has led the beartype library to completely reimplement _ProtocolMeta in order to address the performance issues: https://github.com/beartype/beartype/blob/main/beartype/typing/_typingpep544.py.

I think it's fine to decide that we don't want to bloat the API of typing_extensions, or that it's not our job to backport things just to make them faster. But I'll defend the relevance of the optimisations here to our users; I think the speedup addresses a real problem that's been a common pain point for users of typing.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

Thinking about it more I'm OK with merging this. Performance improvements are new features, and typing-extensions is about backporting new features.

CHANGELOG.md Outdated Show resolved Hide resolved
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
@JelleZijlstra JelleZijlstra merged commit d3719ac into python:main Apr 26, 2023
@AlexWaygood AlexWaygood deleted the fast-protocols branch April 26, 2023 17:18
ShaneMurphy2 pushed a commit to ShaneMurphy2/typing_extensions that referenced this pull request May 17, 2023
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