Skip to content

Fix public symbol lookup perf - #6251

Merged
hoyosjs merged 2 commits into
mainfrom
dev/max-charlamb/paired-public-symbol-lookup
Nov 17, 2026
Merged

hoyosjs merged 2 commits into
mainfrom
dev/max-charlamb/paired-public-symbol-lookup

Conversation

@max-charlamb

@max-charlamb max-charlamb commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Summary

A faster replacement for the public-name reverse lookup introduced in #6242:

  • Select the public name with IDebugAdvanced2.GetSymbolInformation(GET_SYMBOL_NAME_BY_OFFSET_AND_TAG_WIDE, address, SymTagPublicSymbol).
  • Obtain displacement with an ordinary, unfiltered IDebugSymbols3.GetNameByOffsetWide call instead of reverse-resolving the public name with GetOffsetByNameWide.
  • Keep this policy in a module-owned DbgEngModuleSymbols helper, leaving DebuggerServices as the low-level wrapper.
  • Preserve export-only name retry and failure propagation, without changing global symbol options or enumerating/caching module symbols.

Performance

Measured on Windows x64 using a synthetic workload with 100,000 generated methods and 215,422 public PDB symbols:

Approach Warm time/query Startup through first lookup Retained managed-memory delta
Original GetNameByOffset with global PUBLICS_ONLY 17.47 us 36.99 ms 1,600 bytes
Scoped public-name + reverse-lookup algorithm (prior measurement) 1.392 s 1,529 ms 4,224 bytes
This PR: public name + ordinary displacement 24.49 us 75.75 ms 3,120 bytes

The proposed lookup avoids the expensive reverse-name lookup. Compared with the original global-public-only behavior, warm lookup time is approximately 40.2% higher (+7.02 us/query). There is no module-wide symbol cache.

Known correctness limitations

Ordinary lookup can select a private symbol with a different starting address from the selected public symbol. Pairing its displacement with the public name can therefore report an incorrect public-symbol start.

Against an original-public-only reference:

  • All 300,563 generated-method queries matched both name and displacement.
  • Of 343,166 normal reference queries, 343,144 matched and 22 had different displacements. These are native code/data cases; this prototype does not fix them.
  • An additional 474 cross-section <PERF> formatting differences and one before-first-public boundary difference were recorded separately.

Pair public-tag names with ordinary lookup displacement to avoid reverse name resolution. Known symbol-start mismatches remain; this is a prototype.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: 56b7f1ec-323f-44e6-bee9-b2af0e9fc062
@max-charlamb
max-charlamb marked this pull request as ready for review November 16, 2026 21:07
@max-charlamb
max-charlamb requested a review from a team as a code owner November 16, 2026 21:07
Co-authored-by: Copilot <[email protected]>
Copilot-Session: 56b7f1ec-323f-44e6-bee9-b2af0e9fc062
@max-charlamb max-charlamb changed the title Prototype public-name and ordinary-displacement lookup Fix public symbol lookup perf Nov 16, 2026
@hoyosjs

hoyosjs commented Nov 17, 2026

Copy link
Copy Markdown
Member

Are we OK with the correctness displacement issue?

@max-charlamb

Copy link
Copy Markdown
Member Author

Are we OK with the correctness displacement issue?

Yes, as far as I can tell this shouldn't impact any 'managed' code (including NativeAOT).

@hoyosjs

hoyosjs commented Nov 17, 2026

Copy link
Copy Markdown
Member

Have we tested:

  • GetSymbolEntriesByOffset(addr, 0, null, null, 0, out n) and then again with the array of n entries. This gives us displacements.
  • GetSymbolEntryInformation to check for publics.
  • Pick one and do GetSymbolEntryStringWide.

Since I think this PR does have the issue of not picking a particularly stable name in case of folding with ICF (which ILC does do).

@max-charlamb

Copy link
Copy Markdown
Member Author

Have we tested:

  • GetSymbolEntriesByOffset(addr, 0, null, null, 0, out n) and then again with the array of n entries. This gives us displacements.
  • GetSymbolEntryInformation to check for publics.
  • Pick one and do GetSymbolEntryStringWide.

Since I think this PR does have the issue of not picking a particularly stable name in case of folding with ICF (which ILC does do).

Yes, I tried this approach. Unfortunately, GetSymbolEntriesByOffset returns only symbols which contain a range (and the address is within the range). It seems the public symbols don't have ranges and are omitted from this search.

This is unlike the GetNameByOffset, where it finds the nearest preceding symbol.

@hoyosjs

hoyosjs commented Nov 17, 2026

Copy link
Copy Markdown
Member

This is unlike the GetNameByOffset, where it finds the nearest preceding symbol.

I see - this is essentially ln <addr>. I guess this will have to be a tradeoff for now and we'll revisit if we see this starts to hit issues (I can only think of FindPointersIn cases)

@hoyosjs
hoyosjs enabled auto-merge (squash) November 17, 2026 20:18
@hoyosjs
hoyosjs disabled auto-merge November 17, 2026 20:19
@hoyosjs
hoyosjs merged commit bfa7c72 into main Nov 17, 2026
25 checks passed
@hoyosjs
hoyosjs deleted the dev/max-charlamb/paired-public-symbol-lookup branch November 17, 2026 20:19
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