[ty] cache the intersection of two types as a tracked function#23547
Merged
sharkdp merged 2 commits intoastral-sh:mainfrom Feb 25, 2026
Merged
[ty] cache the intersection of two types as a tracked function#23547sharkdp merged 2 commits intoastral-sh:mainfrom
sharkdp merged 2 commits intoastral-sh:mainfrom
Conversation
Typing conformance resultsNo changes detected ✅ |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
Merging this PR will improve performance by 22.17%
Performance Changes
Comparing Footnotes
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
unsupported-operator |
0 | 4 | 0 |
invalid-argument-type |
0 | 2 | 0 |
unresolved-attribute |
0 | 2 | 0 |
| Total | 0 | 8 | 0 |
Contributor
sharkdp
approved these changes
Feb 25, 2026
Contributor
sharkdp
left a comment
There was a problem hiding this comment.
This is great, thank you very much!
I added a docstring that might help developers find from_two_elements when they attempt to call from_elements with two elements only.
AlexWaygood
pushed a commit
that referenced
this pull request
Feb 25, 2026
Similar to #23547 which added `IntersectionType::from_two_elements`, this adds a cached `UnionType::from_two_elements` method that wraps the union of exactly two types in a `#[salsa::tracked]` function. This enables Salsa to memoize two-element union constructions, which are by far the most common case, avoiding redundant work on repeated queries. All non-test callsites of `UnionType::from_elements` that pass exactly two elements have been updated to use the new method. https://claude.ai/code/session_01B8moosqrkcptHVjNT7LvrU
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
From #23201 (comment)
This could bring a significant performance improvement to main, so I'm breaking it out as a standalone PR.
Test Plan
N/A