Repository navigation
Switch to type SymbolName unique.Handle[string] - #64699
Draft
Jake Bailey (jakebailey) wants to merge 7 commits into
Draft
Jake Bailey (jakebailey) wants to merge 7 commits into
Jake Bailey (jakebailey) wants to merge 7 commits into
Conversation
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this |
Contributor
Contributor
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
lspComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
startupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Symbols should share canonical names so identity checks and symbol-table lookups do not repeatedly compare string contents. Preserve textual behavior for diagnostics, emitted output, and the JavaScript API.
Known names and intermediate name operations should stay interned; repeated interning and string round trips defeat the canonical representation in frequently used lookup paths.
Symbol names need their own constructor and representation boundary, without exposing generic string handles throughout the compiler. Give name serialization a lossless escaped spelling and distinguish unset names from valid empty names.
unique.Make registers a weak handle for every new string, which made binding substantially slower and added allocations. Canonical names do not need to be collected during a compilation, so a dedicated table can make interning cheap. Identifying names by a 32-bit ID also keeps them free of pointers, so the symbol tables, nodes, and caches that store them cost the garbage collector nothing to scan or write-barrier.
Binding, checking, and language features reinterned identifier text at every symbol-table lookup, so interning cost was paid many times per identifier and showed up as a large binding regression. Interning once when the identifier is created lets every later lookup use the stored name directly. The AST schema gains a SymbolName field type so the generated Go AST and encoder carry the interned name while the JavaScript API still sees a plain string.
Most identifiers in a file repeat a small set of names, and going to the shared intern table for each one makes parsing noticeably slower, especially when many files are parsed in parallel. A small per-parser cache resolves repeated names without touching shared state.
Jake Bailey (jakebailey)
force-pushed
the
intern-symbol-names
branch
from
October 15, 2026 16:55
23581b2 to
7428ff5
Compare
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Interning every identifier at parse time hashes its text, but the
scanner has just walked the same bytes. Hashing while scanning saves a
second pass over each identifier in the parser's hottest path.
│ sec/op │ sec/op vs base │
Parse/empty.ts-20 610.1n ± 2% 610.2n ± 1% ~ (p=0.767 n=12)
Parse/checker.ts-20 46.61m ± 3% 45.68m ± 3% -1.99% (p=0.005 n=12)
Parse/dom.generated.d.ts-20 16.71m ± 2% 16.53m ± 3% ~ (p=0.178 n=12)
Parse/Herebyfile.mjs-20 786.8µ ± 2% 779.4µ ± 1% ~ (p=0.319 n=12)
Parse/jsxComplexSignatureHasApplicabilityError.tsx-20 218.6µ ± 2% 213.3µ ± 2% -2.41% (p=0.012 n=12)
geomean 606.0µ 598.2µ -1.29%
Member
Author
|
TypeScript Bot (@typescript-bot) perf test this faster |
Contributor
Contributor
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This branch has not been deployed
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.
Symbol names are currently plain
strings. Every identifier, symbol, symbol table key, and name-keyed cache holds its own 16-byte string header, every lookup hashes and compares the full text, and all of those pointers have to be scanned by the GC. On large projects that adds up to a lot of memory and GC work for what is effectively a small set of repeated names.This PR interns symbol names instead:
ast.SymbolNameis now a 32-bit ID into a process-wide, pointer-free intern table, so names cost 4 bytes, compare and hash as integers, and are invisible to the GC.Identifier, so the binder, checker, and language service use it directly rather than reinterning node text on each lookup. The AST schema gains aSymbolNametype; the JS API still sees strings.Perf run: 3.7–13.4% less memory across the suite, mui-docs 10% faster, bind 18–24% faster, and no total-time regressions. Parse is 8–15% slower from hashing each identifier.
Interned names are never freed. That's bounded per program for
tsc, but the table grows over a long language server session.