Skip to content

Optimize LongValueFacetCutter with leaf-local ordinal cache#15898

Open
RamakrishnaChilaka wants to merge 1 commit intoapache:mainfrom
RamakrishnaChilaka:optimise_LongValueFacetCutter
Open

Optimize LongValueFacetCutter with leaf-local ordinal cache#15898
RamakrishnaChilaka wants to merge 1 commit intoapache:mainfrom
RamakrishnaChilaka:optimise_LongValueFacetCutter

Conversation

@RamakrishnaChilaka
Copy link
Copy Markdown
Contributor

Description

LongValueFacetCutter's nextOrd() calls computeIfAbsent() on every document, which acquires a ReadWriteLock.readLock() each time — even when the value has already been seen. With low-cardinality fields (e.g. 1K distinct values across 500K docs), ~99.8% of these lock acquisitions are wasted.

This PR adds a per-leaf LongIntHashMap that caches value → ordinal mappings. On cache hit (the common case), ordinal resolution is a plain unsynchronized hash map get. On cache miss (first occurrence of a value in the segment), it falls through to the existing locked computeIfAbsent and stores the result locally.

JMH Benchmark (500K docs, 1K cardinality, Corretto JDK 25.0.2)

Benchmark Single-valued Multi-valued
matchAll (before) 57.17 ops/s 23.95 ops/s
matchAll (after) 76.44 ops/s (+34%) 30.43 ops/s (+27%)
filteredRange (before) 554.06 ops/s 239.78 ops/s
filteredRange (after) 655.63 ops/s (+18%) 278.14 ops/s (+16%)

@github-actions github-actions bot added this to the 10.5.0 milestone Mar 31, 2026
@RamakrishnaChilaka RamakrishnaChilaka force-pushed the optimise_LongValueFacetCutter branch from 0d0884c to 6be639b Compare March 31, 2026 11:12
@github-actions
Copy link
Copy Markdown
Contributor

This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution!

@github-actions github-actions bot added the Stale label Apr 15, 2026
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.

1 participant