bugfix (Solr 9.x port): Performance degradation for collapse queries with string sort clauses due to enforced LZ4 decompression#4618
Closed
bartoszfidrysiak wants to merge 5 commits into
Conversation
…rdinal fast path comparison for string sorted doc values from the same segment
aac8ca4 to
a36a2a3
Compare
8 tasks
Author
|
Closing for now. According to #4620 (comment), we should first create PR to main so I created #4621. |
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.
https://issues.apache.org/jira/browse/SOLR-XXXXX (not yet created)
Description
Migrating to
Lucene90DocValuesProducerin Solr 9 revealed a significant performance regression in collapse queries sorted by string fields, due to the extra overhead of LZ4 decompression. Solr 9’s collapse implementation does not apply any optimizations and always calls Lucene’sTermOrdValLeafComparator.copy(), which triggersLZ4.decompress()for every document processed by the collapse query. This decompression overhead did not exist in Solr 8.Solution
This PR proposes two improvements:
The first improvement focuses on scenarios where many collapse groups contain only a single document, or where collapse sorting uses multiple fields with a string field acting as a tie-breaker.
The second improvement is expected to deliver major gains in cases where many documents originate from the same segment.
Tests
Four new tests were added in TestCollapseQParserPlugin:
testCollapseStringSortLazyLoadingTieDoesNotEvictGroupHead- verifies that when two documents in the same group have an equal string sort value, the first-seen document remains the group head (a tie must not trigger eviction). Covers both single-segment (ordinal fast path) and multi-segment (slow path) cases.testCollapseStringSortOrdinalFastPathMultiClauseTieBreaking- verifies that when clause-1 of a multi-clause sort ties on ordinal comparison, clause-2 correctly decides the winner. Also exercises the remaining-values copy loop with a cross-segment competitor.testCollapseStringSortWithoutDocValuesSkipsLazyLoadingAndOrdinalFastPath- verifies that sorting on a string field without SORTED DocValues produces correct results via the eager field-comparator path, ensuring the lazy loading and ordinal fast path are safely bypassed when unavailable.testCollapseStringSortOrdinalFastPathDescendingWithMissingValues- verifies that missing values rank last even under a descending sort, where the missing-value sentinel (missingOrd = -1) combined with reverseMul = -1 must still produce the correct ordering in the ordinal fast path.In addition to
TestCollapseQParserPlugin, theCollapsingSearchbenchmark was introduced to compare average execution times for collapse queries across different sort field combinations. In the benchmark, documents from the same groups are distributed evenly across all segments. The benchmark was executed locally on my machine against Solr 9.10.1 and Solr 9.10.1-SNAPSHOT, which includes the enhancements.Conclusions:
collapseByDateAndStrbenchmark shows that Solr 9 SNAPSHOT performs significantly better regardless of the number of segments. This is because the string field serves only as a tiebreaker in the collapse sort, so in most cases comparing dates is sufficient to determine the winner. In addition, string doc values are loaded lazily, which avoids eagerly materializing the string value when it is not needed. According to the benchmark data, the snapshot with the two improvements madecollapseByDateAndStrabout 9 times faster.collapseByStrbenchmark shows that Solr 9 SNAPSHOT delivers significantly better performance only when the number of segments is small, especially when most documents from the same group are located in the same segment. In the single-segment case, string doc values do not need to be materialized to pick a winner, since comparing element ordinals is enough and is both safe and efficient. According to the benchmark data, these two improvements together madecollapseByStrabout 50 times faster for one segment. With many segments, however, and with documents from the same groups spread evenly across them, the ordinal fast path provides no benefit because most comparisons still require string materialization.Checklist
Please review the following and check all that apply:
mainbranch../gradlew check.