Skip to content

Commit 204a1d9

Browse files
committed
Auto merge of rust-lang#120024 - Mark-Simulacrum:fast-union-merge, r=<try>
Merge into larger interval set This reduces the work done while merging rows. In at least one case (rust-lang#50450), we have thousands of union([range], [20,000 ranges]), which previously inserted each of the 20,000 ranges one by one. Now we only insert one range into the right hand set after copying the set over. This cuts the runtime of the test case in rust-lang#50450 from ~26 seconds to ~6 seconds locally, though it doesn't change the memory usage peak (~9.5GB).
2 parents 533cfde + 1696148 commit 204a1d9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

compiler/rustc_index/src/interval.rs

+6
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ impl<I: Idx> IntervalSet<I> {
236236
I: Step,
237237
{
238238
assert_eq!(self.domain, other.domain);
239+
if self.map.len() < other.map.len() {
240+
let backup = self.clone();
241+
self.map.clone_from(&other.map);
242+
return self.union(&backup);
243+
}
244+
239245
let mut did_insert = false;
240246
for range in other.iter_intervals() {
241247
did_insert |= self.insert_range(range);

0 commit comments

Comments
 (0)