mikemccand commented on a change in pull request #1948:
URL: https://github.com/apache/lucene-solr/pull/1948#discussion_r505800348
##########
File path: lucene/core/src/java/org/apache/lucene/index/OrdinalMap.java
##########
@@ -271,13 +273,26 @@ protected boolean lessThan(TermsEnumIndex a,
TermsEnumIndex b) {
globalOrd++;
}
- this.firstSegments = firstSegments.build();
- this.globalOrdDeltas = globalOrdDeltas.build();
+ long ramBytesUsed = BASE_RAM_BYTES_USED + segmentMap.ramBytesUsed();
+ this.valueCount = globalOrd;
+
+ // If the first segment contains all of the global ords, then we can apply
a small optimization
+ // and hardcode the first segments and global ord deltas as all zeroes.
+ if (ordDeltaBits.length > 0 && ordDeltaBits[0] == 0L &&
ordDeltas[0].size() == this.valueCount) {
Review comment:
> > Do we (somewhere, couldn't find it here) pre-sort all segments by
the cardinality descending?
>
> We do in fact -- the segments are sorted by 'weight', which in all call
sites corresponds to the number of unique terms. This was added in
[LUCENE-5782](https://issues.apache.org/jira/browse/LUCENE-5782).
Ahh, so then we know the first segment will indeed have the most unique
terms, and therefore the highest chance of having "all 0s" ord deltas.
I think 2nd and 3rd segments also might have all 0s ord deltas? But we can
try to optimize that in a followon issue ... progress not perfection!
> > Does our PackedLongValues.monotonicBuilder already optimize for the case
where it is all 0s, for the case where another segment (not the first) has all
the global values as well?
>
> When constructing the individual `PackedInts.Reader` instances, we do
identify the all 0s case and use the lightweight `PackedInts.NullReader`. It's
great we optimize that case, but it does mean this PR doesn't make an enormous
space difference.
Got it. Well, it's great that all these layers optimize :)
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]