Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Use a SmallVec for seen type aliases#26187

Merged
MichaReiser merged 1 commit into
mainfrom
micha/use-smallvec-seen-type-aliases
Jun 21, 2026
Merged

[ty] Use a SmallVec for seen type aliases#26187
MichaReiser merged 1 commit into
mainfrom
micha/use-smallvec-seen-type-aliases

Conversation

@MichaReiser

@MichaReiser MichaReiser commented Jun 21, 2026

Copy link
Copy Markdown
Member

Summary

Use a SmallVec for type aliases visited while checking self-referential type-variable defaults.

Running ty over the entire ecosystem corpus shows this distribution

Seen aliases Checks Percentage
0 1,728,178 99.868647%
1 2,051 0.118524%
2 122 0.007050%
3 68 0.003930%
4 29 0.001676%
6 3 0.000173%

A SmallVec with an inline capacity avoids allocations in 99%, and the linear scan is a non-brainer for up to 6 elements. There's a risk that larger seen result in O(n) scans at every level, which would justify a hash map. I'd argue that this isn't an issue in practice and we also accept O(n) for our recursive Type visitor.

I'd say we use a SmallVec, we can always use a SmallSet if this ever shows up on a real world project.

Performance

Consistent 2-3% improvement across all projects

Test Plan

Testing: Ran focused mdtests, repository hooks, and the 162-project ecosystem corpus.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 21, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 21, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@MichaReiser MichaReiser added the performance Potential performance improvement label Jun 21, 2026
@MichaReiser MichaReiser marked this pull request as ready for review June 21, 2026 12:41
@MichaReiser MichaReiser requested a review from a team as a code owner June 21, 2026 12:41
@astral-sh-bot astral-sh-bot Bot requested a review from carljm June 21, 2026 12:41
@MichaReiser MichaReiser merged commit 3a9470a into main Jun 21, 2026
60 checks passed
@MichaReiser MichaReiser deleted the micha/use-smallvec-seen-type-aliases branch June 21, 2026 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants