Skip to content

perf: skip PreprocessLinkSubstitutions when no {{ }} present - #3837

Merged
Mpdreamz merged 1 commit into
mainfrom
perf/preprocess-link-early-exit
Aug 13, 2026
Merged

perf: skip PreprocessLinkSubstitutions when no {{ }} present#3837
Mpdreamz merged 1 commit into
mainfrom
perf/preprocess-link-early-exit

Conversation

@Mpdreamz

Copy link
Copy Markdown
Member

Summary

PreprocessLinkSubstitutions unconditionally runs GetCodeBlockRanges (a full span scan) and Regex.Replace (allocates a new string + a Match+Group object 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 passes
  • dotnet run --project src/tooling/docs-migrate -- bench — record ResolveDirectoryTree time

🤖 Generated with Claude Code

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>
@Mpdreamz
Mpdreamz requested a review from a team as a code owner August 11, 2026 14:11
@Mpdreamz
Mpdreamz requested a review from reakaleek August 11, 2026 14:11
@Mpdreamz Mpdreamz added the fix label Aug 11, 2026
@Mpdreamz
Mpdreamz merged commit 1f050b4 into main Aug 13, 2026
25 of 26 checks passed
@Mpdreamz
Mpdreamz deleted the perf/preprocess-link-early-exit branch August 13, 2026 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants