Edarke opened a new pull request, #16811: URL: https://github.com/apache/lucene/pull/16811
### Description <!-- If this is your first contribution to Lucene, please make sure you have reviewed the contribution guide. https://github.com/apache/lucene/blob/main/CONTRIBUTING.md --> **Problem Statement** While profiling some production deployments at MongoDB, we measured that 25% of all CPU time was spent in vtable lookups in Lucene99HnswVectorsReader.search. This was noted on indexes using SparseVectorValues, and far exceeded vtable overhead for the HNSW path. The performance impact of sparse vector values is abrupt: even 1% of docs missing vector values is sufficient to reproduce the issue. **Solution** First, this change introduces an ENN strategy using `VectorScorer.Bulk`, which provides specialized implementations for sparse and dense vector values. This has two benefits: 1) The `ordToDoc` becomes monomorphic along each scoring path. 2) For highly selective filters (which should be common for ENN), `ConjunctionUtils` is able to select an optimal lead iterator. For unfiltered search, it seems that creating a Bulk scorer has a small but consistently measurable overhead. In this case, we continue using `bulkScore` but add a redundant check on minScore to avoid a relatively expensive call to ordToDoc for sparse vector values. **Benchmarks** \* AI was used to supplement existing benchmarks and aggregate results. ### KnnGraphTester Cohere Single segment (force-merged) | data | filter | main | branch | Δ median | per-round Δ (%) | |--------|--------|------:|-------:|---------:|-------------------------| | dense | none | 1.312 | 1.321 | +0.7% | +1.4 / +0.7 / +0.8 | | dense | 0.1% | 0.260 | 0.064 | −75.4% | −75.4 / −75.8 / −75.2 | | dense | 0.25% | 0.305 | 0.110 | −63.9% | −63.9 / −63.8 / −65.4 | | dense | 1% | 2.948 | 2.928 | −0.7% | +0.8 / −0.7 / −0.1 | | dense | 5% | 2.431 | 2.450 | +0.8% | +1.5 / +0.8 / +0.4 | | dense | 50% | 2.473 | 2.559 | +3.5% | +5.7 / +6.1 / −5.1 | | sparse | none | 1.313 | 1.305 | −0.6% | −12.1 / −0.6 / −0.8 | | sparse | 0.1% | 2.047 | 0.065 | −96.8% | −96.8 / −96.8 / −96.9 | | sparse | 0.25% | 2.162 | 0.122 | −94.4% | −94.1 / −94.4 / −94.3 | | sparse | 1% | 3.866 | 4.033 | +4.3% | +3.8 / +4.3 / +3.5 | | sparse | 5% | 3.603 | 3.619 | +0.4% | −1.5 / +0.2 / +0.8 | | sparse | 50% | 4.456 | 4.484 | +0.6% | +0.2 / +0.6 / +0.5 | -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
