[ty] Cache KnownClass::to_class_literal#22000
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
CodSpeed Performance ReportMerging #22000 will improve performances by 17.44%Comparing Summary
Benchmarks breakdown
Footnotes
|
|
And I have to run all benchmarks one more time |
This comment was marked as resolved.
This comment was marked as resolved.
| class | ||
| .try_to_class_literal_without_logging(db) | ||
| .or_else(|lookup_error| { | ||
| if matches!( |
There was a problem hiding this comment.
I don't think this will be a new issue but we might end up seeing this log message when we hit a salsa cycle because the cycle initial function returns None. I can't think of an easy way to avoid this AND keeping the log message.
|
The perf improvement is a wide range from 0-15% on ty benchmark |
* main: [ty] Document `TY_CONFIG_FILE` (#22001) [ty] Cache `KnownClass::to_class_literal` (#22000) [ty] Fix benchmark assertion (#22003) Add uv and ty to the Ruff README (#21996) [ty] Infer precise types for `isinstance(…)` calls involving typevars (#21999) [ty] Use `FxHashMap` in `Signature::has_relation_to` (#21997) [ty] Avoid enforcing standalone expression for tests in f-strings (#21967) [ty] Use `title` for configuration code fences in ty reference documentation (#21992)
This PR adds salsa caching to
KnownClass::to_class_literal.I noticed that we spend about 4.5% of discord.py's entire check time in
KnownClass::to_class_literalwhich seemed high. That's why I added salsa caching to the lookup and the results are much better than I thought because:KnownClass::Module::to_class_literalends up in a cycle. Adding cycle handling toto_class_literalreduces the size of the cycle.imported_symbol(whichKnownClass::to_class_literaluses resolvesKnownClass::Module.to_instance). It might be worth trying if we can resolve this cycle somehowKnownClass::to_class_literalon the calling query, adding many dependencies to every query that uses aKnownClass. MakingKnownClass::to_class_literala query ensures that we store the dependencies only once, and dependent query only have to depend onKnownClass::to_class_literal. This helps reduce the memo metadata.