Skip to content

Cache normalized file names to avoid re-allocating them per cursor - #708

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:perf-name-resolution-vtbl
Jul 12, 2026
Merged

Cache normalized file names to avoid re-allocating them per cursor#708
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:perf-name-resolution-vtbl

Conversation

@tannergooding

Copy link
Copy Markdown
Member

IsIncludedFileOrLocation runs for every cursor (via IsExcluded) 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 identical work thousands of times per generation.

Cache the normalized name and full name per CXFile, mirroring the existing _fileContents cache -- same key type, populated on miss, cleared per translation unit in GenerateBindings.


Measured on the TerraFX Windows SDK generation (DirectX/d3d12) with DOTNET_TieredCompilation=0 (the NativeAOT-representative full-opt proxy the shipped tool runs under), sampled GCAllocationTick, before vs. after this change:

Before After
Total sampled allocations 179.6 MB 142.7 MB
StringExtensions.NormalizePath 18.0 MB 0
StringExtensions.NormalizeFullPath 8.7 MB 0

~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.

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>
@tannergooding
tannergooding merged commit c8417e7 into dotnet:main Jul 12, 2026
14 checks passed
@tannergooding
tannergooding deleted the perf-name-resolution-vtbl branch July 15, 2026 00:08
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.

1 participant