Skip to content

Add LiveDocs.toFixedBitSet specialization in FixedBitSet.copyOf - #16623

Open
costin wants to merge 4 commits into
apache:mainfrom
costin:lucene/livedocs-copyof
Open

costin wants to merge 4 commits into
apache:mainfrom
costin:lucene/livedocs-copyof

Conversation

@costin

@costin costin commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

After LiveDocs interface was introduced in #15413, FixedBitSet.copyOf fell to per-bit loop execution instead of using the specialized fast paths in Dense/SparseLiveDocs.

This PR addresses that by introducing a toFixedBitSet() method on LiveDocs and a dedicated check in copyOf.
Since there are only two implementations of LiveDocs, both final, the dispatch is bimorphic and inlineable.
copyOf bytecode goes from 90 to 113 bytes, well under the 325-byte FreqInlineSize threshold.

I've included a JMH benchmark and an end-to-end benchmark that measures the impact on SoftDeletesDirectoryReaderWrapper.

Alternative to #16282 which found the same gap but used a different approach.

Since apache#15413, DenseLiveDocs and SparseLiveDocs fall through
to the per-bit generic loop in copyOf. Add toFixedBitSet to
the LiveDocs interface so copyOf can bulk-copy with one
instanceof check instead of walking every document.
@costin

costin commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Forgot the benchmark

CopyOfBenchmark

AMD EPYC 7R32 (c5a.2xlarge), JDK 25, 3 forks, 5 iters x 3s.

DenseLiveDocs:

deletionRate size before (us) after (us) ratio
0.1% 100k 53.1 0.97 54.7x
0.1% 1M 553.6 9.75 56.8x
1% 100k 65.0 0.98 66.3x
1% 1M 594.6 9.81 60.6x
10% 100k 128.3 0.98 130.9x
10% 1M 1249.3 9.95 125.6x

SparseLiveDocs:

deletionRate size before (us) after (us) ratio
0.1% 100k 93.6 1.74 53.8x
0.1% 1M 734.5 17.4 42.2x
1% 100k 119.6 7.19 16.6x
1% 1M 1187.7 79.7 14.9x
10% 100k 219.7 63.0 3.5x
10% 1M 2183.3 730.5 3.0x

Generic Bits fallback (unchanged):

deletionRate size before (us) after (us) ratio
0.1% 100k 59.9 60.1 1.00x
0.1% 1M 481.2 487.2 0.99x
1% 100k 68.3 68.5 1.00x
1% 1M 550.8 549.7 1.00x
10% 100k 130.5 131.5 0.99x
10% 1M 1215.5 1216.9 1.00x

SoftDeletesReaderBenchmark

Same hardware setup.

softDeleteRate numDocs before (us) after (us) ratio
1% 200k 410 31 13.3x
5% 200k 457 81 5.7x
1% 1M 1959 146 13.4x
5% 1M 2241 400 5.6x

@michaeljmarshall michaeljmarshall 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.

LGTM

Comment thread lucene/core/src/java/org/apache/lucene/util/SparseLiveDocs.java Outdated

@Setup(Level.Trial)
public void setup() throws Exception {
tempDir = Path.of(System.getProperty("java.io.tmpdir"), "softdel-bench-" + System.nanoTime());
Replace java.io.File teardown with IOUtils.rm()
and apply google-java-format fixes.
Now that apache#16593 is merged, replace per-doc loop
with bulk applyMask as suggested by review.
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.

3 participants