perf(parser): add collection capacity hints to known-size loops - #1791
Merged
Conversation
hluaguo
force-pushed
the
opt/capacity-hints
branch
from
June 23, 2026 18:25
3685f95 to
7bc6c76
Compare
jglogan
reviewed
Jun 23, 2026
Contributor
Author
|
Oh, the dedupe can shrink the input, so reserving before it over-allocates. I'll shift reserveCapacity after the dedupe in both tmpfsMounts and mounts. |
hluaguo
force-pushed
the
opt/capacity-hints
branch
from
June 24, 2026 11:56
5d6c635 to
7c90357
Compare
hluaguo
force-pushed
the
opt/capacity-hints
branch
from
June 24, 2026 11:57
7c90357 to
071614e
Compare
Code Coverage
|
jglogan
approved these changes
Jun 26, 2026
Contributor
|
@hluaguo Merged, thank you for the optimization! |
saehejkang
pushed a commit
to saehejkang/container
that referenced
this pull request
Jul 16, 2026
…e#1791) - For result sets with known sizes, it's more efficient to supply the size as a capacity hint.
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.
Type of Change
Motivation and Context
Methods in Parser.swift and Utility.swift build arrays and dictionaries in loops where the final size is known from the input parameter count, but none pre-allocate storage. Without a capacity hint, Array.append grows the backing store exponentially (2x), causing O(log n) reallocation+copies per call. These methods execute on every
container run/createcommand, so the savings compound at scale.Testing
Added 7 new tests with large inputs (50-100 entries) that exercise the capacity-allocated code paths. All 183 existing tests pass with zero regressions.