Skip to content

Don't rebuild RegEx on each quoted scalar scan - #1526

Open
MichaelK05-dev wants to merge 1 commit into
jbeder:masterfrom
MichaelK05-dev:perf/reuse-regex
Open

MichaelK05-dev wants to merge 1 commit into
jbeder:masterfrom
MichaelK05-dev:perf/reuse-regex

Conversation

@MichaelK05-dev

@MichaelK05-dev MichaelK05-dev commented Nov 25, 2026 •

Copy link
Copy Markdown

Instead of rebuilding the RegEx on each call, we instantiate it once and keep the existing behaviour the same otherwise. This is only needed for the single quote rule, as it involves dynamic memory allocation due to the subpatterns. I also did it for the double quote rule, just to keep it consistent, but its not really needed there.

AI wasnt used for the implementation, but I let it benchmark the changes, and on YAML documents with a high amount of short single quoted scalars it has some noticeable effects:

24,000 short single-quoted values:

API Before After Parse time reduction
Parser::HandleNextDocument() with a counting handler 25.28 ms 17.41 ms 30%
YAML::Load(std::istream&) 32.01 ms 26.82 ms 16%

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant