Optimize binary search in MutableSparseIntSet.add - #2052
Conversation
Replace the O(n) linear scan used to find the insertion point in MutableSparseIntSet.add with a binary search via the new IntSetUtil.binarySearchInsertionPoint helper, which delegates to java.util.Arrays.binarySearch. This is the inner loop of points-to-set construction, so the change yields large gains on intset-heavy workloads: - SlicerBenchmark.computeBackwardSliceInTestList: ~19% faster - DataflowBenchmark.analyzeTestContextSensitive: ~11% faster - DataflowBenchmark.analyzeTestContextInsensitive: ~8% faster No measurable regression was observed on CallGraphBenchmark.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #2052 +/- ##
============================================
- Coverage 50.81% 50.81% -0.01%
+ Complexity 12761 12760 -1
============================================
Files 1368 1368
Lines 83499 83500 +1
Branches 14414 14414
============================================
- Hits 42431 42428 -3
- Misses 36385 36387 +2
- Partials 4683 4685 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I'm also curious about the reduction in code coverage for |
Astute question! The latter, and that's a problem. I expected that this PR would show even better improvements when applied to the larger arrays introduced by #2051. However, I'm seeing evidence that the opposite is true. Please hold off on approving this PR until I can do a more thorough investigation. We may discover that each change is an improvement by itself, but not when taken together. |
Replace the linear scan used to find the insertion point in
MutableSparseIntSet.addwith a binary search via the newIntSetUtil.binarySearchInsertionPointhelper, which delegates tojava.util.Arrays.binarySearch.This operation is the inner loop of points-to-set construction, so the change yields large gains on
IntSet-heavy workloads:SlicerBenchmark.computeBackwardSliceInTestList: ~19% fasterDataflowBenchmark.analyzeTestContextSensitive: ~11% fasterDataflowBenchmark.analyzeTestContextInsensitive: ~8% fasterNo measurable regression was observed on
CallGraphBenchmark.