[ty] Avoid deriving sequents for typevars with concrete bounds - #27587
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 96.98%. The percentage of expected errors that received a diagnostic held steady at 93.62%. The number of fully passing files held steady at 106/133. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
flake8
trio
|
|
Merging this PR will not alter performance
Performance Changes
Comparing Footnotes
|
31131d6 to
303dd22
Compare
303dd22 to
a8385c6
Compare
| /// | ||
| /// Unlike [`any_over_type`], this reports when the traversal is incomplete because evaluating a | ||
| /// lazy type attribute would be required. | ||
| pub(super) fn try_any_over_type<'db>( |
carljm
left a comment
There was a problem hiding this comment.
Looks good! A few inline comments.
| .iter() | ||
| .chain(constraint_support.iter()) | ||
| .any(|typevar| self.independent_typevars.contains(&typevar)) | ||
| && !self.incomplete_support_constraints.contains(existing) |
There was a problem hiding this comment.
Changing the concrete argument in an eight-variable version of the benchmark to:
type AliasInt = int
x = Invariant[AliasInt]()increases checking time from 0.03 s to 2.64 s; a fully specialized protocol, concrete TypedDict, or NewType takes about 5.2 s.
Do you think it would be worth a follow-up to extend this optimization to aliases, protocols, TypedDicts, or NewTypes, instead of conservatively always adding them to incomplete_support_constraints? I guess the main worry here is the potential for cycles or perf regressions resulting from following lazy attributes?
…l-sh#27587) The constraint solver has a fast-path that bypasses the full solver when all type variables are bounded by concrete types. This was necessary to fix exponential blowup in the sequent map with a large number of type variables with no transitive relationships. astral-sh/ty#3989. However, introducing a single relationship between type variables bypasses the fast path, making it possible to observe similar exponential blowup, as seen in astral-sh#26680. This PR adds a short-circuit in the full solver to avoid sequent discovery for the subset of typevars that have concrete bounds. Note that I attempted to remove the fast-path entirely now that we have a more general fix, but it reintroduced a small regression due to the general extra work that the full solver performs. A followup may be able to close the gap entirely. There are some differences in behavior and diagnostics between the two paths that should eventually be addressed as well. --------- Co-authored-by: Charlie Marsh <charlie.r.marsh@gmail.com>
The constraint solver has a fast-path that bypasses the full solver when all type variables are bounded by concrete types. This was necessary to fix exponential blowup in the sequent map with a large number of type variables with no transitive relationships. astral-sh/ty#3989. However, introducing a single relationship between type variables bypasses the fast path, making it possible to observe similar exponential blowup, as seen in #26680. This PR adds a short-circuit in the full solver to avoid sequent discovery for the subset of typevars that have concrete bounds.
Note that I attempted to remove the fast-path entirely now that we have a more general fix, but it reintroduced a small regression due to the general extra work that the full solver performs. A followup may be able to close the gap entirely. There are some differences in behavior and diagnostics between the two paths that should eventually be addressed as well.