Skip to content

Remove redundant file deletion - #11

Merged
SimonCropp merged 1 commit into
SimonCropp:masterfrom
atifaziz:x-del
Mar 8, 2019
Merged

Remove redundant file deletion#11
SimonCropp merged 1 commit into
SimonCropp:masterfrom
atifaziz:x-del

Conversation

@atifaziz

@atifaziz atifaziz commented Mar 8, 2019

Copy link
Copy Markdown
Contributor

The file deletion this PR suggests to remove is entirely redundant because File.CreateText later 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):

  • Fewer and superfluous change notifications for file watchers
  • The creation date/time of the file that existed is maintained and just the last write time updated
  • Fewer disk I/O (existence check + deletion + re-creation) or less (including code) is more
  • Atomic

@SimonCropp

Copy link
Copy Markdown
Owner

good find

@SimonCropp
SimonCropp merged commit 4b8bc58 into SimonCropp:master Mar 8, 2019
@SimonCropp SimonCropp added this to the 9.0.3 milestone Mar 8, 2019
@SimonCropp

Copy link
Copy Markdown
Owner

This is now deployed. NuGet may take some time to make it available for download.

@atifaziz
atifaziz deleted the x-del branch March 8, 2019 12:46
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.
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.

2 participants