Grow ArrayCollection geometrically when inserting at an index - #106
Open
rotundtapir wants to merge 1 commit into
Open
rotundtapir wants to merge 1 commit into
rotundtapir wants to merge 1 commit into
Conversation
add(index, item) went through slideRight(), which reserved exactly the missing slot, so every insertion reallocated and copied the whole array. Building a type block entry by entry, as merging tables does, was quadratic because of it. Also fix ensureCapacity(int) allocating too little when some capacity is already free: it subtracted the free slots from the request and then added the result to the size instead of to the current length, which could leave fewer free slots than asked for.
Owner
|
I can't merge because i blocked |
rotundtapir
force-pushed
the
pr/array-collection-growth
branch
from
September 28, 2026 20:07
308e74e to
163afc3
Compare
Author
|
Done, the commit is rewritten without the co-author line, same code. Thanks for taking a look! |
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.
add(index, item)goes throughslideRight(), which reserves exactly the missing slot, so inserting n items one at a time copies the array n times. Building a type block entry by entry, asTableBlock.merge()does, is quadratic because of it. With this change alone,ApkBundle.mergeModules()on the split bundle of the Google app (com.google.android.googlequicksearchbox 17.61.20, 87 MB resources.arsc) spends 16 s merging instead of 39 s.It also fixes
ensureCapacity(int)allocating too little when some capacity is already free. It subtracted the free slots from the request and then added the result to the size instead of the current length, so it could leave fewer free slots than asked for.ArrayCollectionTestcovers both.Independent of #104. It's the first of three split-merge changes; the other two (merging bundle tables without copying the base table, and less memory per table entry) will follow separately.