Skip to content

Optimize ParallelLeafReader to improve term vector fetching efficienc #14373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lucene/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Optimizations
---------------------
* GITHUB#14011: Reduce allocation rate in HNSW concurrent merge. (Viliam Durina)
* GITHUB#14022: Optimize DFS marking of connected components in HNSW by reducing stack depth, improving performance and reducing allocations. (Viswanath Kuchibhotla)
* GITHUB#14373: Optimized `ParallelLeafReader` to improve term vector fetching efficiency.

Bug Fixes
---------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,15 +348,24 @@ public void prefetch(int docID) throws IOException {
@Override
public Fields get(int docID) throws IOException {
ParallelFields fields = null;
for (Map.Entry<String, LeafReader> ent : tvFieldToReader.entrySet()) {
String fieldName = ent.getKey();
TermVectors termVectors = readerToTermVectors.get(ent.getValue());
Terms vector = termVectors.get(docID, fieldName);
if (vector != null) {

// Step 2: Fetch all term vectors once per reader
for (Map.Entry<LeafReader, TermVectors> entry : readerToTermVectors.entrySet()) {
TermVectors termVectors = entry.getValue();
Fields docFields = termVectors.get(docID); // Fetch all fields at once

if (docFields != null) {
if (fields == null) {
fields = new ParallelFields();
}
fields.addField(fieldName, vector);

// Step 3: Aggregate only required fields
for (String fieldName : docFields) {
Terms vector = docFields.terms(fieldName);
if (vector != null) {
fields.addField(fieldName, vector);
}
}
}
}

Expand Down