[ty] Store cycle-detector cache entries inline#26183
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe 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. |
Memory usage reportMemory usage unchanged ✅ |
|
Wow, 1423 is larger than I would have guessed. I wonder if we could (separately) experiment with using a fancier cache that has some kind of LRU cache eviction. My guess would be that some small portion of those 1423 entries are repeatedly hit, while most are hit rarely, if at all |
I'm not sure this is worth it. This adds another write to the cached paths and the cost is relatively low, because we don't store |
|
I still think experimenting could be interesting, but it's definitely out of scope here |
|
Sure. We just see in Salsa that LRU cache has a high cost because it adds a write to every read path. But, the scales are probably different here. |
f2b3ec3 to
bb6d6d0
Compare
Merging this PR will improve performance by 5.25%
Performance Changes
Tip Curious why this is faster? Use the CodSpeed MCP and ask your agent. Comparing Footnotes
|
Summary
We always push at least one type into the
CycleDetectorcache, even if that was the only typed that needed visiting.This PR adds an inline storage that avoids allocating for the most common cases.
As you can see, most
CycleDetector(90%) contain at most two cached elements. That's what this PR uses as inline cache. We keep using aFxHashMapfor cases with more than two elements.I also considered using a
SmallVec, butcachecan grow largeBenchmarks
Codspeed reports about a 2-3% perf improvement for most projects
Test Plan
Testing: Passed the ty semantic test suite, Clippy, repository hooks, and wall-time benchmarks.