ruff
3a9470a6 - [ty] Use a SmallVec for seen type aliases (#26187)

Commit
79 days ago
[ty] Use a SmallVec for seen type aliases (#26187) ## 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.
Author
Parents
Loading