Repository navigation
Conversation
validateIndentColumn runs for every character of a literal or folded
block scalar, and it parsed the header option each time. Without an
indentation indicator (the common "|" or ">"), that is
strconv.ParseInt(""), which returns a *strconv.NumError: one
allocation of 48 bytes per character.
The indicator is now parsed once, when the multi-line state is set up.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #986 +/- ##
=======================================
Coverage 80.65% 80.66%
=======================================
Files 22 22
Lines 6845 6847 +2
=======================================
+ Hits 5521 5523 +2
Misses 905 905
Partials 419 419 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Before submitting your PR, please confirm the following.
Purpose
MultiLineState.validateIndentColumnis called for every character of a literal or folded block scalar, and it calledfirstLineIndentColumnByOpt(s.opt)each time. For a header without an indentation indicator (|,>,|-,>+, …),that is
strconv.ParseInt(""), which returns a*strconv.NumError: one allocation of 48 bytes per character of the text.This PR parses the indicator once, in
setLiteralandsetFolded, and keeps it inMultiLineState.optIndentColumn.Behaviour does not change.
Unmarshalling a document with a literal block of 2,030 characters into
map[string]any(Apple M2, Go 1.26.9, 6 runs):We came across it while profiling a CMS that parses a few thousand pages with text blocks on every publish: two thirds of
all bytes allocated were these errors.
Test
TestBlockScalarAllocations(lexer) tokenizes block scalars of 10 and of 10,000 characters and requires about the samenumber of allocations. Before the change it was 67 against 20,054, after it 46 against 52.
make test(with the YAML testsuite) and
golangci-lint runpass.🤖 Generated with Claude Code