perf: skip PreprocessLinkSubstitutions when no {{ }} present - #3837
Merged
Conversation
The MatchEvaluator callback only rewrites links whose URL contains {{ }}.
Across the 435k-file corpus only a small fraction of files use attribute
substitutions, so both GetCodeBlockRanges (a full span scan) and the
Regex.Replace (allocates a new string + a Match+Group per link) were
dead work on the vast majority of files.
Adding an early-return guard eliminates both allocations for every file
that does not contain {{ at all.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
reakaleek
approved these changes
Aug 12, 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.
Summary
PreprocessLinkSubstitutionsunconditionally runsGetCodeBlockRanges(a full span scan) andRegex.Replace(allocates a new string + aMatch+Groupobject per link) on every markdown file. The callback only rewrites links whose URL contains{{; on a corpus where the vast majority of files have no attribute substitutions at all, both operations are pure overhead.Adding an early-return guard eliminates both allocations for every file that does not contain
{{.Test plan
dotnet test tests/Elastic.Markdown.Tests/ --filter SubstitutionTest|MutationOperatorsInLinksTest— 7 tests pass (covers the link-substitution path)dotnet test tests/Elastic.Markdown.Tests/— full 1951-test suite passesdotnet run --project src/tooling/docs-migrate -- bench— recordResolveDirectoryTreetime🤖 Generated with Claude Code