Cache the union of two types as a tracked function#23565
Merged
AlexWaygood merged 1 commit intomainfrom Feb 25, 2026
Merged
Conversation
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
UnionType::from_two_elements for binary union constructionUnionType::from_two_elements
Typing conformance resultsNo changes detected ✅ |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
Merging this PR will improve performance by 6.37%
Performance Changes
Comparing Footnotes
|
UnionType::from_two_elements
carljm
approved these changes
Feb 25, 2026
Contributor
|
This happened to fix astral-sh/ty#2834 on my machine. I assume that's "random"? |
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.
The same as #23547, but for unions rather than intersections. Similar to #23547, this appears to bring across-the-board performance improvements without significant memory-usage increases.