-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[ty] WIP: accelerate fixed-point convergence of recursively defined literal types #21683
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
base: main
Are you sure you want to change the base?
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
CodSpeed Performance ReportMerging #21683 will degrade performances by 9.91%Comparing Summary
Benchmarks breakdown
Footnotes
|
|
Hmm, for example, when inspecting the following code, I see a clear performance improvement locally, but the change on codspeed seems less clear: class Counter:
def __init__(self: "Counter"):
self.count = 0
def increment(self: "Counter"):
self.count = self.count + 1
reveal_type(Counter().count) # revealed: Unknown | intmain: # release
$ hyperfine -i "ty check widen.py"
Benchmark 1: ty check widen.py
Time (mean ± σ): 103.3 ms ± 8.6 ms [User: 56.9 ms, System: 45.0 ms]
Range (min … max): 96.4 ms … 136.6 ms 22 runs
# debug
$ hyperfine -i "ty check widen.py"
Benchmark 1: ty check widen.py
Time (mean ± σ): 899.9 ms ± 6.2 ms [User: 849.7 ms, System: 51.9 ms]
Range (min … max): 889.4 ms … 910.3 ms 10 runs# release
$ hyperfine -i "ty check widen.py"
Benchmark 1: ty check widen.py
Time (mean ± σ): 59.6 ms ± 9.2 ms [User: 26.5 ms, System: 37.8 ms]
Range (min … max): 52.5 ms … 95.7 ms 31 runs
# debug
$ hyperfine -i "ty check widen.py"
Benchmark 1: ty check widen.py
Time (mean ± σ): 267.2 ms ± 4.1 ms [User: 222.2 ms, System: 55.6 ms]
Range (min … max): 261.6 ms … 276.5 ms 10 runs |
|
Conversely, the apparent performance degradation is due to increasing The performance impact of changing 190: https://codspeed.io/astral-sh/ruff/runs/compare/6929edd91e804897641888e6..6929fa9ed77b771deb1a9244 |
…e performance diff" This reverts commit 961c578.
Summary
Closes astral-sh/ty#957
As explained in astral-sh/ty#957, literal union types for recursively defined values can be widened early to speed up the convergence of fixed-point iterations.
This PR achieves this by embedding a marker in
UnionTypethat distinguishes whether a value is recursively defined.This also allows us to identify values that are not recursively defined, so I've increased the limit on the number of elements in a literal union type for such values.
Test Plan
call/union.mdhas been updated