Avoid unnecessary memory allocation in PackedLongValues#Iterator (#13439)

We always allocate a long array of page size for a new PackedLongValues#Iterator instance, which is not necessary when packing a small number of values. this is more evident in the scenario of high-frequency flush operations
This commit is contained in:
Zhang Chao 2024-06-04 13:03:09 +08:00 committed by GitHub
parent c132e95369
commit 801b822972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View File

@ -249,7 +249,8 @@ Improvements
Optimizations
---------------------
(No changes)
* GITHUB#13439: Avoid unnecessary memory allocation in PackedLongValues#Iterator. (Zhang Chao)
Bug Fixes
---------------------

View File

@ -138,7 +138,7 @@ public class PackedLongValues extends LongValues implements Accountable {
int currentCount; // number of entries of the current page
Iterator() {
currentValues = new long[pageMask + 1];
currentValues = new long[(int) Math.min(size, pageMask + 1)];
vOff = pOff = 0;
fillBlock();
}