Use ArrayDeque for JapaneseCompletionFilter output buffering#16416
Open
luizmlima wants to merge 1 commit into
Open
Use ArrayDeque for JapaneseCompletionFilter output buffering#16416luizmlima wants to merge 1 commit into
luizmlima wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
JapaneseCompletionFilter.CompletionTokenGeneratorusesoutputsas a FIFO queue.The current implementation uses an
ArrayListwithremove(0), which shifts the remaining elements after each removal. This change replaces it with anArrayDequeand usesaddLast()andremoveFirst().There is no change to the public API or to the generated tokens, their order, offsets, or position increments.
Benchmark
I used JMH to compare the current
ArrayListimplementation with the proposedArrayDequeimplementation.The benchmark runs the full
JapaneseCompletionAnalyzerpipeline. For each input, it creates a token stream and consumes all generated tokens.Both versions were tested with the same benchmark code, JDK, JVM options, hardware, and JMH configuration.
Configuration
-Xms1g -Xmx1g -XX:+AlwaysPreTouchLower values are better.
Environment
Temurin-25.0.3+97.0.11-76070011-genericx86_64Inputs
東京ドラえもんシンシンシンシンシンシンシンシンThe first two are short, more typical inputs. The last two were included to generate larger output batches and make the queue behavior more visible.
Results
東京ドラえもんシンシンシンシンシンシンシンシンNegative values mean that
ArrayDequecompleted the operation in less time.For the shorter inputs, the error ranges overlap, so there was no meaningful performance difference.
For the larger output batches,
ArrayDequeperformed better:シンシンシンシンシンシンシンシンThe largest case went from
8.288 ± 0.138 us/opwithArrayListto7.743 ± 0.079 us/opwithArrayDeque.This matches the way the collection is used.
ArrayList.remove(0)shifts the remaining elements, whileArrayDeque.removeFirst()does not.The change does not improve typical short inputs in a measurable way, but it better matches the FIFO access pattern and avoids the increasing cost of repeated removals from the beginning of an
ArrayList.Validation
The following commands completed successfully:
./gradlew tidy./gradlew -p lucene/analysis/kuromoji test --tests "org.apache.lucene.analysis.ja.TestJapaneseCompletionFilter"./gradlew -p lucene/analysis/kuromoji test --tests "org.apache.lucene.analysis.ja.TestJapaneseCompletionAnalyzer"./gradlew -p lucene/analysis/kuromoji check./gradlew check