Skip to content

Micro-optimize TypeTraverserVisitor #19459

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 1 commit into from
Jul 17, 2025
Merged

Micro-optimize TypeTraverserVisitor #19459

merged 1 commit into from
Jul 17, 2025

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jul 16, 2025

Specialize for concrete sequence types (list and tuple) for faster iteration, since the traversal code is very hot.

I used trace logging (#19457) to identify functions where PyObject_GetIter was called frequently.

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

Specialize for concrete sequence types (`list` and `tuple`) for faster
iteration, since the traversal code is very hot.

I used log tracing (#19457) to identify functions where
PyObject_GetIter was called frequently.

This is a aart 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:53
JukkaL added a commit that referenced this pull request Jul 16, 2025
Specialize a hot for loop for the concrete `tuple` and `list` types.
Also add a fast path for empty type arguments.

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%.
Copy link
Contributor

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

JukkaL added a commit that referenced this pull request Jul 17, 2025
Specialize a hot for loop for the concrete `tuple` and `list` types.
Also add a fast path for empty type arguments.

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%.
@JukkaL
Copy link
Collaborator Author

JukkaL commented Jul 17, 2025

This is very similar to #19461, which is already merged, so I won't wait for a separate code review here.

@JukkaL JukkaL merged commit 8bd159b into master Jul 17, 2025
20 checks passed
@JukkaL JukkaL deleted the opt-1 branch July 17, 2025 09:14
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.

1 participant