perf: make strict-mode key tracking allocation-free on valid documents#1102
Open
pelletier wants to merge 1 commit into
Open
perf: make strict-mode key tracking allocation-free on valid documents#1102pelletier wants to merge 1 commit into
pelletier wants to merge 1 commit into
Conversation
The KeyTracker materialized a string for every key part pushed — one allocation per part per table header, on every document, even though the strings are only ever read when an unknown-key error is actually recorded. The tracker now keeps the raw part bytes (valid for the lifetime of the document being parsed) and materializes strings only when an error snapshot is taken. Resetting the tracker also reuses its stack storage across pooled decodes instead of dropping it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 11, 2026
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.
Splitting #1088: this PR carries one optimization technique so its impact and review surface stay isolated. Stacked on #1101 (only to keep the diffs disjoint — the change itself is independent).
What
The strict-mode
KeyTrackermaterialized a string for every key part pushed — one allocation per part per table header, on every document, even though the strings are only ever read when an unknown-key error is actually recorded. The tracker now keeps the raw part bytes (valid for the lifetime of the document being parsed) and materializes strings only when an error snapshot is taken (Key()); resetting also reuses the stack storage across pooled decodes instead of dropping it.Impact
Benchmarked on a dedicated linux/amd64 spot VM (t2d), go1.26.4, interleaved A/B vs the base of this PR, benchstat over 10 samples per side:
Marshal/SimpleDocument/map: -3.80%RealWorldGolangciStrict: -3.55%Marshal/ReferenceFile/map: -2.41%Unmarshal/SimpleDocument/map: -2.08%UnmarshalDataset/config: -1.95%RealWorldHugoFrontMatterBatch: -1.93%RealWorldContainerdConfig: +2.07%RealWorldGolangciStrict: -29.17%Full benchstat (sec/op, allocs/op)
sec/op
allocs/op
This is a decode-only change; the
Marshal/*movements are code-alignment noise. The headline is the allocation column: −29% allocs/op on the strict-mode benchmark (RealWorldGolangciStrict).🤖 Generated with Claude Code