jpountz commented on a change in pull request #1948: URL: https://github.com/apache/lucene-solr/pull/1948#discussion_r503705206
########## File path: lucene/core/src/java/org/apache/lucene/index/OrdinalMap.java ########## @@ -359,10 +375,9 @@ public long ramBytesUsed() { @Override public Collection<Accountable> getChildResources() { List<Accountable> resources = new ArrayList<>(); - resources.add(Accountables.namedAccountable("global ord deltas", globalOrdDeltas)); - resources.add(Accountables.namedAccountable("first segments", firstSegments)); resources.add(Accountables.namedAccountable("segment map", segmentMap)); - // TODO: would be nice to return actual child segment deltas too, but the optimizations are confusing + // TODO: would be nice to return the ordinal and segment maps too, but it's not straightforward + // because of optimizations. Review comment: could be do something like `if (firstSegments != LongValues.ZEROES) { resources.add(Accountables.namedAccountable("first segments", firstSegments)); }`? ########## 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) { + this.firstSegments = LongValues.ZEROES; + this.globalOrdDeltas = LongValues.ZEROES; + ramBytesUsed += RamUsageEstimator.shallowSizeOf(LongValues.ZEROES); Review comment: We could ignore it completely from `ramBytesUsed`, since this singleton is allocated anyway, regardless of whether the optimization uses it. ---------------------------------------------------------------- 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: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org