Skip to content

Micro-optimize type indirection visitor #19460

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Micro-optimize type indirection visitor #19460

wants to merge 1 commit into from

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 16, 2025

Specialize iteration for the concrete types list and tuple, since this is faster than iterating over an abstract iterable in compiled code. Also avoid constructing many temporary lists.

Duplicate some very hot code in the hopes further improving performance slightly, through inlining and possibly also better branch prediction.

The approach is similar to what I used in #19459.

This is a part of a set of micro-optimizations that improve self check performance by ~5.5%.

Specialize iteration for the concrete types `list` and `tuple`,
since this is faster than iterating over an abstract iterable
in compiled code.

Duplicate some very hot code in the hopes further improving
preformance slightly, through inlining and possibly also better
branch prediction.

This is a part of a set of micro-optimizations that improve self check
performance by ~5.5%.
@JukkaL JukkaL requested a review from ilevkivskyi July 16, 2025 12:57
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Interesting, I would never guess this is a hot code path.

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.

2 participants