Repository navigation
perf: amortize ReaderParser retained-buffer growth - #294
Open
anishpentyala wants to merge 2 commits into
Open
anishpentyala wants to merge 2 commits into
anishpentyala wants to merge 2 commits into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
Description
When a retained value spans many read chunks,
readMorecurrently allocates exactly enough room for one more chunk and copies the entire retained prefix each time. This makes copying quadratic in the number of chunks.Grow capacity geometrically instead, using the required capacity when that is larger. The requested read size and the existing discard behavior are unchanged. The tradeoff is spare retained-buffer capacity, up to roughly 2x the capacity immediately needed in the worst case.
Added a deterministic growth regression, compatibility controls for long strings, escaped values, composite values, long keys,
ArrayEachcallbacks and reader errors, plus a retained-value benchmark. The growth test fails on the baseline with 128 reallocations for 128 reads at both tested chunk sizes, and passes after the change.Benchmark before / after
Local exploratory medians from five runs of three iterations each, Go 1.26.6 linux/amd64,
GOMEMLIMIT=256MiB GOMAXPROCS=2, benchmarkBenchmarkReaderParserRetainedValuewith-benchmem -benchtime=3x -count=5:Validation
TestOracleSetPr286Regressionfailures, tracked separately in Test failures forTestOracleSetPr286Regression#288 and test: assert OOB Set is retrieved at the last index #290. The full ordinary suite passes with that known failing test excluded. Baseline also excludes the new growth regression that demonstrates this fix.go vethas the same existing unreachable-code andreflect.StringHeaderwarnings on baseline and candidate. A 386 build is blocked on both by existing integer-overflow constants inobligation_property_test.go.