Remove allocated_size from RepeatedPtrFieldBase::Rep.#26880
Draft
copybara-service[bot] wants to merge 1 commit intomainfrom
Draft
Remove allocated_size from RepeatedPtrFieldBase::Rep.#26880copybara-service[bot] wants to merge 1 commit intomainfrom
allocated_size from RepeatedPtrFieldBase::Rep.#26880copybara-service[bot] wants to merge 1 commit intomainfrom
Conversation
This comes with wins in a few places, notably that we don't need to maintain `allocated_size` when adding/removing elements, simplifying common methods like `Add`. Without `allocated_size`, we need some other way to distinguish the end of allocated entries from uninitialized entries in the heap rep. Instead of leaving the remainder of `Rep` uninitialized after the last allocated element, we memset all of `Rep` to 0 when resizing. This change comes with a slight regression to resize, which now needs to memset the remainder of the newly allocated rep to 0. Additionally, the destructor, when destroying cleared elements (unlikely), has to iterate until it finds a null element, which is an additional few instructions. The most glaring regression is in `ReleaseLast`/`UnsafeArenaReleaseLast`/`CloseGap`, which all need to calculate `AllocatedSize` in order to move any allocated elements from the end to the front, maintaining the invariant that all allocated elements immediately follow the last exposed element. They call `AllocatedSizeSlow`, which either does a linear scan of the elements, or a binary search, depending on how large the search range is. PiperOrigin-RevId: 899189917
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.
Remove
allocated_sizefromRepeatedPtrFieldBase::Rep.This comes with wins in a few places, notably that we don't need to maintain
allocated_sizewhen adding/removing elements, simplifying common methods likeAdd.Without
allocated_size, we need some other way to distinguish the end of allocated entries from uninitialized entries in the heap rep. Instead of leaving the remainder ofRepuninitialized after the last allocated element, we memset all ofRepto 0 when resizing.This change comes with a slight regression to resize, which now needs to memset the remainder of the newly allocated rep to 0. Additionally, the destructor, when destroying cleared elements (unlikely), has to iterate until it finds a null element, which is an additional few instructions.
The most glaring regression is in
ReleaseLast/UnsafeArenaReleaseLast/CloseGap, which all need to calculateAllocatedSizein order to move any allocated elements from the end to the front, maintaining the invariant that all allocated elements immediately follow the last exposed element. They callAllocatedSizeSlow, which either does a linear scan of the elements, or a binary search, depending on how large the search range is.