Cache normalized file names to avoid re-allocating them per cursor - #708
Merged
tannergooding merged 1 commit intoJul 12, 2026
Merged
Conversation
IsIncludedFileOrLocation runs for every cursor and re-derives the file's normalized name from scratch each time -- file.Name.ToString().NormalizePath(), plus a NormalizeFullPath() (Path.GetFullPath) on the traversal-name path. The same file recurs for every cursor it contains, so this repeats the same work thousands of times. Cache the normalized name and full name per CXFile, mirroring the existing _fileContents cache (same key type, cleared per translation unit in GenerateBindings). On the TerraFX Windows SDK d3d12 generation this drops sampled allocations from 179.6 MB to 142.7 MB (~20%), eliminating the 18.0 MB of NormalizePath and 8.7 MB of NormalizeFullPath entirely. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
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.
IsIncludedFileOrLocationruns for every cursor (viaIsExcluded) and re-derives the file's normalized name from scratch each time --file.Name.ToString().NormalizePath(), plus aNormalizeFullPath()(Path.GetFullPath) on the traversal-name path. The same file recurs for every cursor it contains, so this repeats identical work thousands of times per generation.Cache the normalized name and full name per
CXFile, mirroring the existing_fileContentscache -- same key type, populated on miss, cleared per translation unit inGenerateBindings.Measured on the TerraFX Windows SDK generation (
DirectX/d3d12) withDOTNET_TieredCompilation=0(the NativeAOT-representative full-opt proxy the shipped tool runs under), sampledGCAllocationTick, before vs. after this change:StringExtensions.NormalizePathStringExtensions.NormalizeFullPath~20% fewer allocations overall; both normalization frames drop out of the profile entirely. All 3706 generator tests pass and the build is warning-clean.
Note
This PR body was drafted by Copilot.