Skip to content

[6.0] Improve RangeSet union performance #74996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 6, 2024

Conversation

natecook1000
Copy link
Member

Cherry pick of #74963 for Swift 6.0.

The existing implementation of `RangeSet.formUnion` performs a naive
insertion of each range of one range set into the other. This
requires shuffling the array of ranges down with each insertion, which
can have quadratic performance.

This change uses the known invariants of the ranges array to instead
perform the merge in linear time. Each range in the resulting array
is determined by finding the next lowest bound between the two range
sets, and then searching for the first upper bound that isn't included
in the merged range set contents.

rdar://129296438
@natecook1000 natecook1000 requested a review from a team as a code owner July 5, 2024 19:04
@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@stephentyrone stephentyrone merged commit 1c0623a into release/6.0 Jul 6, 2024
5 checks passed
@stephentyrone stephentyrone deleted the swift6-rangeset-formunion-perf branch July 6, 2024 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants