Remove redundant file deletion - #11
Merged
Merged
Conversation
Owner
|
good find |
Owner
|
This is now deployed. NuGet may take some time to make it available for download. |
SimonCropp
added a commit
that referenced
this pull request
Jul 7, 2026
Three behavior-preserving allocation reductions on always-on paths. Each was
measured with GC.GetAllocatedBytesForCurrentThread and produces byte-identical
output; the full snapshot suite stays green.
- GetLanguageFromPath: span-based Path.GetExtension + a single lowercasing
string.Create, replacing GetExtension + TrimStart('.') + ToLowerInvariant
(3 string allocations -> 1). 71.2 -> 28.8 B/call. Called for every file
during discovery and again per snippet source file.
- MarkdownProcessor toc checks: line.Current.TrimStart() == "toc" ->
span SequenceEqual, dropping a trimmed-string allocation on every indented
line.
- Line.LeadingWhitespace: computed lazily. Only snippet / web-snippet lines
ever read it, but the ctor allocated a leading-whitespace substring for every
indented line in the document.
Wins 2 and 3 together cut ~13.5% of the allocations when applying an
indentation-heavy document. Adds OptimizationBenchmarks3 (#11
GetLanguageFromPath, #12 indented Apply) to the existing benchmark suite.
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.
The file deletion this PR suggests to remove is entirely redundant because
File.CreateTextlater will either create the file or open the existing one with all content reset to empty. Removing the redundant deletion has the following benefits (in order of descending importance as I see it):