Improve performance symmetry of Set.intersect#19292
Draft
aw0lid wants to merge 2 commits intodotnet:mainfrom
Draft
Improve performance symmetry of Set.intersect#19292aw0lid wants to merge 2 commits intodotnet:mainfrom
aw0lid wants to merge 2 commits intodotnet:mainfrom
Conversation
Contributor
❗ Release notes required
Warning No PR link found in some release notes, please consider adding it.
|
Member
|
Benchmark will need to be a bdn, to see how it performs in jitted code, with proper preheat, etc. |
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.
Optimize Set.intersect for Symmetric Performance & Identity Preservation
Problem (#19139)
Set.intersectin F# currently shows significant performance asymmetry when intersecting sets of very different sizes:a) and checks membership in the second set (b).Huge(a) ∩ Tiny(b)is orders of magnitude slower thanTiny(a) ∩ Huge(b).a).Solution
This PR introduces a size-based heuristic and optimized traversal:
a) to preserve identity.Benchmark Results
Tested on Linux x64, .NET 10.0.1 (Release build, BenchmarkDotNet).
Note: Performance is now symmetric; execution time follows
O(M log N)whereMis the size of the smaller set.Verification Code
This snippet validates both performance and identity preservation; it can be copy-pasted directly in F# Interactive or a test project.
Checklist