-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Improve performance for Tantivy indexValues call
indexValues was falling way behind Lucene due to a few reasons: 1. We were copying results directly into Java objects, which was incurring a lot of JNI back and forth overhead 2. When querying the entire index we were looking at docs instead of the reverse index, which increased the count of items to process This PR does a few things: 1. Add perf benchmarks for the missing functions 2. Add a new IndexCollector trait that can be used to walk the index vs docs 3. Remove the JNI object usage in indexValues vs byte serialized data 4. Glue all these optimizations togther. With this Tantivy is still a bit behind Lucene for this path, but it's almost 100x faster than before.
- Loading branch information
Showing
6 changed files
with
247 additions
and
42 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
43 changes: 43 additions & 0 deletions
43
core/src/rust/tantivy_utils/src/collectors/index_collector.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
//! Collector that can run over an entire index without a query | ||
//! | ||
use tantivy::{collector::SegmentCollector, Searcher, SegmentReader, TantivyError}; | ||
|
||
use super::limited_collector::{LimitCounter, LimitedCollector, LimitedSegmentCollector}; | ||
|
||
/// Index Segment collector | ||
pub trait IndexCollector: LimitedCollector | ||
where | ||
Self::Child: LimitedSegmentCollector, | ||
{ | ||
/// Colllect data across an entire index segment | ||
fn collect_over_index( | ||
&self, | ||
reader: &SegmentReader, | ||
limiter: &mut LimitCounter, | ||
) -> Result<<Self::Child as SegmentCollector>::Fruit, TantivyError>; | ||
} | ||
|
||
pub fn collect_from_index<C>(searcher: &Searcher, collector: C) -> Result<C::Fruit, TantivyError> | ||
where | ||
C: IndexCollector, | ||
C::Child: LimitedSegmentCollector, | ||
{ | ||
let segment_readers = searcher.segment_readers(); | ||
let mut fruits: Vec<<C::Child as SegmentCollector>::Fruit> = | ||
Vec::with_capacity(segment_readers.len()); | ||
|
||
let mut limiter = LimitCounter::new(collector.limit()); | ||
|
||
for segment_reader in segment_readers.iter() { | ||
let results = collector.collect_over_index(segment_reader, &mut limiter)?; | ||
|
||
fruits.push(results); | ||
|
||
if limiter.at_limit() { | ||
break; | ||
} | ||
} | ||
|
||
collector.merge_fruits(fruits) | ||
} |
This file contains 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
Oops, something went wrong.