ruff
82bb2810 - [ty] Speed up materialization of nested generic types (#30462)

Commit
5 hours ago
[ty] Speed up materialization of nested generic types (#30462) Checking nested calls to a generic overload can spend most of its time materializing the same type arguments repeatedly. For a type such as `Row[Row[Any]]` with a covariant parameter, each layer could visit its argument twice to compute the same top materialization. This doubles the work with each layer. Compute the top materialization lazily and reuse it when comparing the argument with its materialization or constructing the result. This also skips the top traversal when only the bottom materialization is needed. Improves astral-sh/ty#5041. ## Test plan I timed the reproducer from the issue on macOS arm64 using an optimized debug build. Checking eight nested overloaded calls went from 29.05 s to 1.55 s. To isolate materialization from overload resolution, I also checked `Top` applied to 23 nested `Row` types. That went from 3.08 s to 0.03 s. Both examples passed before and after the change.
Author
Parents
Loading