Reduce heap usage in BestBucketsDeferringCollector #105444
Open
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.
BestBucketsDeferringCollector delays the creation of sub-aggregations by collecting on the heap the values of documents and buckets received in LeafBucketCollector#collect(int doc, long bucket). Those values are replayed in a later stage if necessary.
We are currently using Lucene PackedLongValues to compress those integers on heap. In #103624 we added PFOR-delta for compression of postings in Elasticsearch which is probably more space efficient that the algorithm in PackedLongValues which is essentially a FOR (without the P) so likely more wasteful.
This PR introduces PForLongValues which follows the PackedLongValues API so it can easily replace the current usage of PackedLongValues in BestBucketsDeferringCollector.