Skip to content

Optimize IndexedDISI by implementing binary search for sparseDocs in …#16349

Open
rajat315315 wants to merge 3 commits into
apache:mainfrom
rajat315315:advanceWithinBlock_opt
Open

Optimize IndexedDISI by implementing binary search for sparseDocs in …#16349
rajat315315 wants to merge 3 commits into
apache:mainfrom
rajat315315:advanceWithinBlock_opt

Conversation

@rajat315315

@rajat315315 rajat315315 commented Jul 2, 2026

Copy link
Copy Markdown

Fixes #16348

Description

This fix would be particularly useful in the case when we are accessing targetDoc which belong to the same block.
In that case, we won't need to do a linear search over the 4096 Docs in the worst case. It would take only 12 operations log(N).

In the worst case, where the block is SPARSE and there are 4096 DocIds stored in it and we need to get all docs.. we would be using advance() function call which would need to call advanceWithinBlock() 4096 times totalling the number of operations to ~8 million.

@rajat315315

Copy link
Copy Markdown
Author

I have run the AdvanceBenchmark JMH suite to evaluate the impact of the new binary search implementation on IndexedDISI.The results demonstrate that the inlinedBranchlessBinarySearch approach provides a performance improvement over the existing linearSearch implementation.
Benchmark Comparison (Throughput):

Throughput Comparison

Benchmark Method Main (ops/ms) PR (ops/ms)
linearSearch 137.506 ± 3.883 133.743 ± 5.126
binarySearch 50.563 ± 1.069 50.215 ± 1.523
inlinedBranchlessBinarySearch N/A 143.826 ± 11.544
  • Baseline (linearSearch): 137.506 ops/ms
  • Optimized (inlinedBranchlessBinarySearch): 143.826 ops/ms
  • Improvement: ~4.6% increase in throughput.

Existing methods (linearSearch and binarySearch) showed no significant performance degradation on the PR branch compared to main, ensuring that these changes are safe for current workloads.
These benchmarks were performed using OpenJDK 25.0.3 with consistent JMH parameters (5 warmup iterations, 10 measurement iterations, 3 forks).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize IndexedDISI by implementing binary search for sparseDocs in advance methods

1 participant