Commit Graph

37702 Commits

Author SHA1 Message Date
Adrien Grand 6e78f379d9 Fix TestPostingsUtil#testIntegerOverflow failure. (#13979)
The group vint logic is mistakenly using the long->int conversion logic for the
case when integers are being written rather than longs.

Closes #13978
2024-11-06 11:35:07 +01:00
Armin Braun 8ed71b3e1c Simplify leaf slice calculation (#13893)
No need to go through the indirection of 2 wrapped functions, just put the logic in plain
methods. Also, we can just outright set the field if there's no executor.
2024-11-06 10:44:43 +01:00
Adrien Grand 9a14d573c8 Adjust expectations of TestTopFieldCollectorEarlyTermination after #13943. 2024-11-05 23:54:07 +01:00
Adrien Grand 48026bbc25 Remove `supportsConcurrency` flag from top-docs collector managers. (#13977)
Our collector managers have a `supportsConcurrency` flag to optimize the case
when they are used in a single thread. This PR proposes to remove this flag now
that the optimization doesn't do much as a result of #13943.
2024-11-05 15:37:36 +01:00
Ignacio Vera 7f50732cc3 Avoid performance regression by constructing lazily the PointTree in NumericComparator (#13498) (#13877) 2024-11-05 12:11:25 +01:00
Luca Cavanna 7e97503eef Revert "Disjunction as CompetitiveIterator for numeric dynamic pruning (#13221)" (#13857) (#13971)
This reverts commit 1ee4f8a111.

We have observed performance regressions that can be linked to #13221. We will need to revise the logic that such change introduced in main and branch_10x. While we do so, I propose that we bake it out of branch_10_0 and we release Lucene 10 without it.

Closes #13856
2024-11-05 12:01:29 +01:00
Greg Miller c29dd588e4 A few small tweaks to VectorUtil#findNextGEQ: (#13972)
1. Rearrange/rename the parameters to be more idiomatic (e.g., follow conventions of Arrays#... methods)
2. Add assert to ensure expected sortedness we may rely on in the future (so we're not trappy)
3. Migrate PostingsReader to call VectorUtil instead of VectorUtilSupport (so it benefits from the common assert)
2024-11-04 16:13:26 -08:00
Adrien Grand 8ae03d66ad Move postings back to int[] to take advantage of having more lanes per vector. (#13968)
In Lucene 8.4, we updated postings to work on long[] arrays internally. This
allowed us to workaround the lack of explicit vectorization (auto-vectorization
doesn't detect all the scenarios that we would like to handle) support in the
JVM by summing up two integers in one operation for instance.

With explicit vectorization now available, it looks like we can get more
benefits from the ability to compare multiple intetgers in one operations than
from summing up two integers in one operation. Moving back to ints helps
compare 2x more integers at once vs. longs.
2024-11-04 18:40:53 +01:00
panguixin 584387a254 Replace Map<String,Object> with IntObjectHashMap for KnnVectorsReader (#13763) 2024-10-31 16:16:44 +01:00
Adrien Grand cff28d546f Speed up advancing within a block, take 2. (#13958)
PR #13692 tried to speed up advancing by using branchless binary search, but while this yielded a speedup on my machine, this yielded a slowdown on nightly benchmarks.

This PR tries a different approach using vectorization. Experimentation suggests that it speeds up queries that advance to the next few doc IDs, such as `AndHighHigh`.
2024-10-31 16:16:44 +01:00
Adrien Grand 8b87527f03 Speed up Lucene912PostingsReader nextDoc() impls. (#13963)
127 times out of 128, nextDoc() returns the next doc ID in the buffer.
Currently, we check if the current doc is equal to the last doc ID in the block
to know if we need to refill. We can do better by comparing the current index
in the block with the block size, which is a bit more efficient since the
latter is a constant.
2024-10-29 18:17:08 +01:00
panguixin 4581add24b replace Map<String,Object> with IntObjectHashMap for DV producer (#13961) 2024-10-29 17:34:06 +01:00
Adrien Grand af9177a598 Remove HitsThresholdChecker. (#13943)
`TopScoreDocCollectorManager` has a dependency on `HitsThresholdChecker`, which
is essentially a shared counter that is incremented until it reaches the total
hits threshold, when the scorer can start dynamically pruning hits.

A consequence of this removal is that dynamic pruning may start later, as soon
as:
 - either the current slice collected `totalHitsThreshold` hits,
 - or another slice collected `totalHitsThreshold` hits and the current slice
   collected enough hits (up to 1,024) to check the shared
   `MaxScoreAccumulator`.

So in short, it exchanges a bit more work globally in favor of a bit less
contention. A longer-term goal of mine is to stop specializing our
`CollectorManager`s based on whether they are going to be used concurrently or
not.
2024-10-28 15:52:13 +01:00
Adrien Grand 054c60e83b Remove LeafSimScorer abstraction. (#13957)
`LeafSimScorer` is a specialization of a `SimScorer` for a given segment. It
doesn't add much value, but benchmarks suggest that it adds measurable overhead
to queries sorted by score.
2024-10-26 13:48:19 +02:00
ljak 0e918ce9bb Ensure stability of clause order for DisjunctionMaxQuery toString (#13944)
Co-authored-by: Laurent <jakubinal@lexum.com>
2024-10-25 18:22:22 +02:00
Adrien Grand 9fb87b606b Disable exchanging minimum scores across slices for exhaustive evaluation. (#13954)
When `totalHitsThreshold` is `Integer.MAX_VALUE`, dynamic pruning is never used
and all hits get evaluated. Thus, the minimum competitive score always stays at
zero, and there is nothing to exchange across slices.
2024-10-25 14:02:26 +02:00
Benjamin Trent ef2b8131cf Ensure doc order for TestCommonTermsQuery#testMinShouldMatch (#13953) 2024-10-25 07:43:26 -04:00
Shubham Chaudhary e8c2218c3a Make some BooleanQuery methods public and a new `#add(Collection)` method for BQ builder (#13950) 2024-10-25 13:33:23 +02:00
Adrien Grand c788be34f1 Remove some useless code in TopScoreDocCollector. (#13955) 2024-10-25 13:33:23 +02:00
Adrien Grand e2c7b1ebed Add MIGRATE entry about the fact that readVLong() may now read up to 10 bytes. (#13956)
This may be of interest for custom `DataInput`/`IndexInput` implementations
that extend `readVLong()`.
2024-10-25 13:33:23 +02:00
Lu Xugang 85fbe6e327 Check ahead if we can get the count (#13899)
Currently, we traverse the BKD tree or perform a binary search using DocValues first, and then check whether the count can be obtained in the count() method of IndexSortSortedNumericDocValuesRangeQuery.

we should consider providing a mechanism to perform this check beforehand, avoid unnecessary processing when dealing with a sparseRange
2024-10-25 15:20:52 +08:00
Adrien Grand 555c7d2ef2 Introduce a heuristic to amortize the per-window overhead in MaxScoreBulkScorer. (#13941)
It is sometimes possible for `MaxScoreBulkScorer` to compute windows that don't
contain many candidate matches, resulting in more time spent evaluating maximum
scores per window than evaluating candidate matches on this window.

This PR introduces a heuristic that tries to require at least 32 candidate
matches per clause per window to amortize the per-window overhead. This results
in a speedup for the `OrMany` task.
2024-10-22 16:54:40 +02:00
Adrien Grand ff03379eb6 Reduce the compiled size of the collect() method on `TopScoreDocCollector`. (#13939)
This comes from observations on https://tantivy-search.github.io/bench/ for
exhaustive evaluation like `TOP_100_COUNT`. `collect()` is often inlined, but
other methods that we'd like to see inlined like `PostingsEnum#nextDoc()` are
not always inlined. This PR decreases the compiled size of `collect()` to make
more room for other methods to be inlined.

It does so by moving an assertion to `AssertingScorable` and extracting an
uncommon code path to a method.
2024-10-22 16:54:40 +02:00
Adrien Grand 2b33b9f3f5 Move BooleanScorer to work on top of Scorers rather than BulkScorers. (#13931)
I was looking at some queries where Lucene performs significantly worse than
Tantivy at https://tantivy-search.github.io/bench/, and found out that we get
quite some overhead from implementing `BooleanScorer` on top of `BulkScorer`
(effectively implemented by `DefaultBulkScorer` since it only runs term queries
as boolean clauses) rather than `Scorer` directly.

The `CountOrHighHigh` and `CountOrHighMed` tasks are a bit noisy on my machine,
so I did 3 runs on wikibigall, and all of them had speedups for these two
tasks, often with a very low p-value.

In theory, this change could make things slower when the inner query has a
specialized bulk scorer, such as `MatchAllDocsQuery` or a conjunction. It does
feel right to optimize for term queries though.
2024-10-21 16:55:50 +02:00
linfn 58f65cc69b Fix StoredFieldsConsumer finish (#13927) 2024-10-21 16:55:49 +02:00
Armin Braun 9f7ef105db Speedup OrderIntervalsSource some more (#13937)
Follow-up to #13871, getting another speedup from relatively trivial changes:

* avoid redundant `end()` call by directly storing the end value for sub-iterator that we don't use for anything else
    * also save most `get(...)` calls for this sub-iterator
* avoid redundant `start()` call by grabbing `start()` directly from `nextInterval`
* replace `getFirst()` with `get(0)`, it looks nice but has needless overhead in my testing (not sure why, but profiling clearly shows it to be slower, maybe just a result of having `get()`'s code hot in the cache with a higher likelihood or something esoteric like that)
* avoid using an iterator for loop for a random access list, this is probably the biggest win in this PR
2024-10-21 16:38:39 +02:00
Armin Braun 75cdf22100 Simplify PForUtil construction and cleanup its code gen a little (#13932)
Generate cleaner code for PForUtil that has no dead parameters.

Also:
PForUtil instances always create their own `ForUtil`, so we can inline
that into the field declaration. Also, we can save cycles
for accessing the input on PostingsDecodingUtil.

Surprisingly, the combination of these cleanups yields a small but
statistically fully visible speedup that the compiler isn't able to get
to on its own it seems.
2024-10-21 15:20:18 +02:00
Armin Braun 750d53c4d3 Use RandomAccessInput instead of seeking in Lucene90DocValuesProducer (#13894)
We use manual seeking and reading instead of random access in this class.
That seems just unnecessarily complicated.
2024-10-21 15:11:19 +02:00
Ignacio Vera 051997b166 Use growNoCopy when copying bytes in BytesRefBuilder (#13930) 2024-10-21 07:37:35 +02:00
Adrien Grand 1a7514f9dd Revert "Better handle dynamic pruning when the leading clause has a single impact block. (#13904)"
This reverts commit 92c4f51224.
2024-10-16 15:15:27 +02:00
Armin Braun cebf1e7259 Avoid slicing memory segments unnecessarily (#13906)
No point in copying the memory segment instances when slicing, they are stateless.
2024-10-15 20:57:50 +02:00
Adrien Grand 7a14a77d90 Skip madvise calls on tiny inner files of compound files. (#13917)
This commit skips `madvise` calls on inner files of compound files that are
smaller than the page size.
2024-10-15 16:18:05 +02:00
Adrien Grand 92c4f51224 Better handle dynamic pruning when the leading clause has a single impact block. (#13904)
`BlockMaxConjunctionBulkScorer` only checks if it can early exit based on
impacts once per window, and windows are computed using impact blocks of the
leading clause. So this logic is defeated if the leading clause produces a
single block (e.g. `ConstantScoreQuery`). This commit addresses this problem by
artificially lowering the window size to contain ~128 docs of the leading
clause.
2024-10-15 16:17:37 +02:00
zhouhui 5727b8ce59 Optimize convert byte2int. (#13889) 2024-10-15 16:13:06 +02:00
Adrien Grand 8ad66899bc Make MaxScoreBulkScorer repartition scorers when the min competitive increases. (#13800)
MaxScoreBulkScorer partitions scorers into a set of essential scorers and a set
of non-essential scorers, depending on the maximum scores produced by scorers
and on the current minimum competitive score. An increase of the minimum
competitive score has the potential to yield a more favorable partitioning, but
repartitioning can also be expensive.

In order to repartition when necessary while avoiding to repartition too often,
this PR tracks the minimum value of the minimum competitive score that would
produce a more favorable partitioning, and repartitions scorers whenever the
minimum competitive score exceeds this threshold.
2024-10-15 15:20:55 +02:00
Adrien Grand b8bfffa368 Only call madvise when necessary. (#13907)
This commit tries to save calls to `madvise` which are not necessary, either
because they map to the OS' default, or because the advice would be overridden
later on anyway. I have not noticed specific problems with this, but it seems
desirable to keep calls to `madvise` to a minimum.

As a consequence:
 - Files that are open with `ReadAdvice.NORMAL` do not call `madvise` since
   this is the OS' default.
 - Compound files are always open with `ReadAdvice.NORMAL`, and the actual is
   only set when opening sub files of these compound files.

To make the latter less trappy, the `IOContext` parameter has been removed from
`CompoundFormat#getCompoundReader`.
2024-10-15 14:14:45 +02:00
Luca Cavanna fbe5757d4c Align TestGenerateBwcIndices.java with AddBackcompatindices.py (#13911)
We updated TestGenerateBwcIndices to create int7 HNSW indices instead of int8 with #13874.
The corresponding python code part of the release wizard needs to be updated accordingly.
2024-10-15 13:40:43 +02:00
Luca Cavanna ac972a97c1 Add back-compat indices for 10.0.0 2024-10-14 23:03:51 +02:00
Luca Cavanna 0f8f1a1ca4 Add 10.0.1 section to CHANGES.txt 2024-10-14 22:10:24 +02:00
Luca Cavanna b45624fafc Update year in copyright 2024-10-14 18:00:25 +02:00
Armin Braun 28798e8768 Dry up EverythingEnum and BlockDocsEnum in Lucene912PostingsReader (#13901)
It's in the title, extracting shared parts across both classes.
Almost exclusively mechanical changes with the exception of the introduction
of an array summing util.
2024-10-14 17:34:34 +02:00
Nhat Nguyen 518c76b51a
Avoid allocating liveDocs for no soft-deletes (#13895) (#13903)
Backport of #13895 to 10x

This is a continuation of #13588, where we avoided allocating liveDocs 
for segments that have the __soft_deletes field but no values in it.
However, that PR only addressed the reading side. This change fixes the
writing scenario with IndexWriter.

Relates #13588
2024-10-14 07:39:31 -07:00
Luca Cavanna 97bfd8b673 DOAP changes for release 10.0.0 2024-10-14 14:58:05 +02:00
Prudhvi Godithi 0651e69fb2 IndexOrDocValuesQuery in query highlighting (#13902)
Signed-off-by: Prudhvi Godithi <pgodithi@amazon.com>
2024-10-14 14:30:10 +02:00
Armin Braun e99db4e954 Dry up both the two ImpactsEnum Implementation ins Lucene912PostingsReader (#13892)
These two share a lot of code, in particular the impacts implementation is 100% identical.
We can save a lot of code and potentially some cycles for method invocations by
drying things up. The changes are just mechanical field movements with the following exceptions:

1. One of the two implementations was using a bytes ref builder, one a bytes ref for holding the
serialized impacts. The `BytesRef` variant is faster so I used that for both when extracting.
2. Some simple arithmetic simplifications around the levels that should be obvious.
3. Removed the the logic for an index without positions in `BlockImpactsPostingsEnum`, that was dead code,
we only set this thing up if there's positions.
2024-10-12 15:52:52 +02:00
Armin Braun a6a6519ee7 Lazy initialize ForDeltaUtil and ForUtil in Lucene912PostingsReader (#13885)
Lazy initialize these fields. They consume/cause a lot of memory/GC because they are
allocated frequently (~7% of all allocations in luceneutil's wikimedia medium run for me).
This does not cause any measurable slowdown as far as runtime is concerned and since these are not
even needed for all instances (in fact they are rarely used in the queries the benchmark explores)
save qutie a few CPU cycles for collecting and allocating them.
2024-10-12 12:43:27 +02:00
panguixin 8180f43678 Remove broken .toArray from Long/CharObjectHashMap entirely (#13884) 2024-10-11 08:52:06 +02:00
Dawid Weiss af3200ae34 Remove broken .toArray from IntObjectHashMap entirely (#13876) 2024-10-11 08:51:55 +02:00
Rene Groeschke d888f6d5a7 Make generated archive files reproducible (#13835)
* Make generated archive files reproducible

This should ensure deterministic archive files and fix issues with changing checksums even
though the codebase has not changed
2024-10-10 11:50:18 +02:00
zhouhui 9a3467d352 Add reopen method in PerThreadPKLookup (#13596)
Co-authored-by: Adrien Grand <jpountz@gmail.com>
2024-10-10 10:30:58 +02:00