Skip to content

Optimize binary search in MutableSparseIntSet.add - #2052

Open
liblit wants to merge 1 commit into
wala:masterfrom
liblit:perf/optimize-binarySearch-over-int-arrays
Open

Optimize binary search in MutableSparseIntSet.add#2052
liblit wants to merge 1 commit into
wala:masterfrom
liblit:perf/optimize-binarySearch-over-int-arrays

Conversation

@liblit

@liblit liblit commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Replace the 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 operation 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.

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.
@liblit
liblit requested a review from msridhar August 31, 2026 18:42
@liblit liblit self-assigned this Aug 31, 2026
@liblit
liblit enabled auto-merge August 31, 2026 18:42
@codecov

codecov Bot commented Aug 31, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 38.46154% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.81%. Comparing base (8a541c9) to head (24685fa).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...main/java/com/ibm/wala/util/intset/IntSetUtil.java 33.33% 4 Missing and 4 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@msridhar msridhar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I'm curious, are the performance improvement numbers given here in addition to those from #2051? Or were these numbers in comparison to the master branch without #2051?

@msridhar

Copy link
Copy Markdown
Member

I'm also curious about the reduction in code coverage for IntSetUtil, though sadly codecov is not able to show me the differences right now...

@liblit

liblit commented Sep 1, 2026

Copy link
Copy Markdown
Contributor Author

are the performance improvement numbers given here in addition to those from #2051? Or were these numbers in comparison to the master branch without #2051?

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.

@liblit
liblit disabled auto-merge September 1, 2026 14:47
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