Cache splitOffsets list to avoid repeated allocations#15625
Open
kuldeep27396 wants to merge 4 commits intoapache:mainfrom
Open
Cache splitOffsets list to avoid repeated allocations#15625kuldeep27396 wants to merge 4 commits intoapache:mainfrom
kuldeep27396 wants to merge 4 commits intoapache:mainfrom
Conversation
BaseFile.splitOffsets() was creating a new List<Long> wrapper on every invocation via ArrayUtil.toUnmodifiableLongList(). When file metadata is read and rewritten (e.g., during manifest rewriting or format conversion), each entry needlessly allocates a list that is immediately consumed and discarded. This change caches the List<Long> representation after the first conversion, similar to how other fields like partitionData are handled. The cache is transient so it won't be serialized. Fixes apache#15622
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.
Why this change
Resolves #15622
Problem: BaseFile.splitOffsets() was creating a new List wrapper on every invocation via ArrayUtil.toUnmodifiableLongList(). When file metadata is read and rewritten (e.g., during manifest rewriting or format conversion), each entry needlessly allocates a list that is immediately consumed and discarded.
Solution: Cache the List representation after the first conversion, similar to how other fields like partitionData are handled. The cache is transient so it won't be serialized.
Changes
Performance Impact
This eliminates unnecessary object allocations when:
The change is minimal and focused, following the existing pattern used for other cached fields in the class.