Skip to content

Conversation

natecook1000
Copy link
Member

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 4, 2024 04:59
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 force-pushed the rangeset-formunion-perf branch from 54c25d0 to ea394e4 Compare July 4, 2024 05:00
@natecook1000
Copy link
Member Author

@swift-ci Please smoke test

@natecook1000
Copy link
Member Author

@swift-ci Please test

@natecook1000 natecook1000 merged commit 6d4f4a4 into main Jul 8, 2024
@natecook1000 natecook1000 deleted the rangeset-formunion-perf branch July 8, 2024 14:00
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.

1 participant