Repository navigation
Optimized insertion-ordered symbol tables - #64979
Conversation
Type ids are creation order, and --generateTrace writes every type a checker creates in id order. Three places create types while they iterate a symbol table, whose iteration order varies from run to run, so the type files differed between runs of the same program: - getInferTypeParameters gets the declared type of each infer type parameter in map order. The result is already sorted; the types are now created in symbol order too. - getNamedMembers checks whether each member is a value, which can resolve an alias, in map order and sorts afterwards. The members are now sorted first. - getAliasForSymbolInContainer and buildExternalModuleContainerIndex resolve every export in map order. Exports that are not aliases still resolve in map order, since that has no side effects; aliases are now resolved last, sorted. The results of all four functions are unchanged.
A symbol's key in a table is not always its name: a module augmentation can merge a named declaration into a default export, which stays keyed "default". extendExportSymbols and createAccessFromSymbolChain use the key, so the helper passes it along with the symbol, and sorts aliases by key when they compare equal.
|
TypeScript Bot (@typescript-bot) test it |
There was a problem hiding this comment.
🟡 Changes recommended
Repeated deletions rebuild the full hash index, making large reused signature-scope cleanup quadratic and allocation-heavy.
1 open issue
What changed in this PR
This PR reduces symbol-table storage in the native TypeScript compiler while preserving insertion order introduced by #64916. Renamed entries use proxy symbols so ordinary entries need only a symbol pointer.
Changes:
- Introduces compact ordered symbol tables with linear lookup for small tables and hash indexing for larger tables.
- Migrates compiler, language-server, and API consumers to the new table operations.
- Adds regression fixtures and baselines for deterministic diagnostics, declaration emit, and export resolution.
| File | Description |
|---|---|
tsc/testdata/tests/cases/compiler/noFlakyExportEqualsWithOtherExportsImportOrder.ts |
Tests export-assignment import ordering. |
tsc/testdata/tests/cases/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.ts |
Tests export-assignment checking order. |
tsc/testdata/tests/cases/compiler/noFlakyDiagnosticsSpellingSuggestionOrder.ts |
Tests resolution order during spelling suggestions. |
tsc/testdata/tests/cases/compiler/noFlakyDiagnosticsNonExportedMemberOrder.ts |
Tests non-exported-member diagnostic stability. |
tsc/testdata/tests/cases/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrderReexportedTypes.ts |
Tests namespace ordering through re-exported types. |
tsc/testdata/tests/cases/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.ts |
Tests namespace-member resolution ordering. |
tsc/testdata/tests/cases/compiler/noFlakyDiagnosticsExportStarDeclarationCollisionOrder.ts |
Tests star-export declaration collision ordering. |
tsc/testdata/tests/cases/compiler/noFlakyDiagnosticsExportStarCollisionOrder.ts |
Tests star-export alias collision ordering. |
tsc/testdata/tests/cases/compiler/noFlakyDeclarationEmitVariableMatchesInScopeOrder.ts |
Tests scope matching during declaration emit. |
tsc/testdata/tests/cases/compiler/noFlakyDeclarationEmitUmdGlobalAliasesOrder.ts |
Tests global-alias ordering during declaration emit. |
tsc/testdata/tests/cases/compiler/noFlakyDeclarationEmitRenamedExportOrder.ts |
Tests renamed-export declaration ordering. |
tsc/testdata/tests/cases/compiler/noFlakyDeclarationEmitLateBoundIndexSignatureSiblingsOrder.ts |
Tests late-bound member resolution ordering. |
tsc/testdata/tests/cases/compiler/noFlakyDeclarationEmitExternalModuleContainerIndexOrder.ts |
Tests module-container indexing order. |
tsc/testdata/tests/cases/compiler/noFlakyDeclarationEmitExportEqualsQualifiedNameOrder.ts |
Tests export-assignment qualification ordering. |
tsc/testdata/tests/cases/compiler/namespaceMembersResolutionOrderExportStar.ts |
Tests explicit versus star-export resolution order. |
tsc/testdata/tests/cases/compiler/exportStarSkipsNamedDefaultExport.ts |
Tests exclusion of merged default exports. |
tsc/testdata/tests/cases/compiler/declarationEmitExternalModuleContainerIndexDeclarationOrder.ts |
Tests declaration order rather than name order. |
tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsImportOrder.types |
Records import-order type results. |
tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsImportOrder.js |
Records import-order declaration output. |
tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.types |
Records checking-order type results. |
tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.symbols |
Records checking-order symbol results. |
tsc/testdata/baselines/reference/compiler/noFlakyExportEqualsWithOtherExportsCheckOrder.errors.txt |
Records checking-order diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsSpellingSuggestionOrder.types |
Records spelling-resolution type results. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsSpellingSuggestionOrder.errors.txt |
Records spelling-resolution diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNonExportedMemberOrder.types |
Records non-exported-member type results. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNonExportedMemberOrder.errors.txt |
Records non-exported-member diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrderReexportedTypes.errors.txt |
Records re-exported-type diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.symbols |
Records namespace-resolution symbols. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsNamespaceMembersResolutionOrder.errors.txt |
Records namespace-resolution diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarDeclarationCollisionOrder.types |
Records declaration-collision types. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarDeclarationCollisionOrder.errors.txt |
Records declaration-collision diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarCollisionOrder.types |
Records alias-collision types. |
tsc/testdata/baselines/reference/compiler/noFlakyDiagnosticsExportStarCollisionOrder.errors.txt |
Records alias-collision diagnostics. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitVariableMatchesInScopeOrder.types |
Records scope-matching types. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitVariableMatchesInScopeOrder.symbols |
Records scope-matching symbols. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitVariableMatchesInScopeOrder.js |
Records scope-matching declaration output. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitUmdGlobalAliasesOrder.types |
Records global-alias types. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitUmdGlobalAliasesOrder.js |
Records global-alias declaration output. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitRenamedExportOrder.types |
Records renamed-export types. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitRenamedExportOrder.js |
Records renamed-export declaration output. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitLateBoundIndexSignatureSiblingsOrder.types |
Records late-bound member types. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitLateBoundIndexSignatureSiblingsOrder.symbols |
Records late-bound member symbols. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitLateBoundIndexSignatureSiblingsOrder.js |
Records late-bound declaration output. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExternalModuleContainerIndexOrder.types |
Records module-container type results. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExternalModuleContainerIndexOrder.js |
Records module-container declaration output. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExportEqualsQualifiedNameOrder.types |
Records export-assignment qualification types. |
tsc/testdata/baselines/reference/compiler/noFlakyDeclarationEmitExportEqualsQualifiedNameOrder.js |
Records qualified declaration output. |
tsc/testdata/baselines/reference/compiler/namespaceMembersResolutionOrderExportStar.symbols |
Records star-export resolution symbols. |
tsc/testdata/baselines/reference/compiler/namespaceMembersResolutionOrderExportStar.errors.txt |
Records star-export resolution diagnostics. |
tsc/testdata/baselines/reference/compiler/exportStarSkipsNamedDefaultExport.types |
Records default-export filtering types. |
tsc/testdata/baselines/reference/compiler/exportStarSkipsNamedDefaultExport.symbols |
Records default-export filtering symbols. |
tsc/testdata/baselines/reference/compiler/exportStarSkipsNamedDefaultExport.js |
Records default-export filtering emit. |
tsc/testdata/baselines/reference/compiler/exportStarSkipsNamedDefaultExport.errors.txt |
Records rejected default-export leakage. |
tsc/testdata/baselines/reference/compiler/declarationEmitExternalModuleContainerIndexDeclarationOrder.types |
Records declaration-ordered type results. |
tsc/testdata/baselines/reference/compiler/declarationEmitExternalModuleContainerIndexDeclarationOrder.js |
Records declaration-ordered emit results. |
tsc/internal/transformers/declarations/transform.go |
Migrates declaration-transform table operations. |
tsc/internal/printer/namegenerator.go |
Migrates local-name lookup. |
tsc/internal/modulespecifiers/specifiers.go |
Migrates ambient export lookup. |
tsc/internal/ls/findallreferences.go |
Migrates reference-search table access. |
tsc/internal/ls/definition.go |
Migrates constructor lookup. |
tsc/internal/ls/completions.go |
Migrates completion iteration and lookup. |
tsc/internal/ls/codeactions_fixclassincorrectlyimplementsinterface.go |
Migrates inherited-member tables. |
tsc/internal/ls/autoimport/extract.go |
Migrates auto-import export traversal. |
tsc/internal/execute/incremental/affectedfileshandler.go |
Migrates exported-enum traversal. |
tsc/internal/checker/utilities.go |
Migrates shared symbol-table helpers. |
tsc/internal/checker/types.go |
Migrates structured-type member access. |
tsc/internal/checker/types_test.go |
Adapts intersection tests to table operations. |
tsc/internal/checker/symbolaccessibility.go |
Migrates accessibility and alias traversal. |
tsc/internal/checker/services.go |
Migrates scope and property collection. |
tsc/internal/checker/nodebuilderscopes.go |
Migrates temporary-scope insertion and cleanup. |
tsc/internal/checker/nodebuilderimpl.go |
Migrates symbol-chain table access. |
tsc/internal/checker/nodebuilder_hover.go |
Migrates namespace hover traversal. |
tsc/internal/checker/jsx.go |
Migrates JSX attribute tables. |
tsc/internal/checker/inference.go |
Migrates inferred-member table construction. |
tsc/internal/checker/exports.go |
Uses insertion order for index siblings. |
tsc/internal/checker/emitresolver.go |
Migrates augmentation and index-member traversal. |
tsc/internal/binder/nameresolver.go |
Migrates name-resolution lookups. |
tsc/internal/binder/binder.go |
Migrates symbol declaration and binding operations. |
tsc/internal/ast/utilities.go |
Uses the new table constructor. |
tsc/internal/ast/symbolflags.go |
Adds the internal name-proxy flag. |
tsc/internal/ast/symbol.go |
Implements compact insertion-ordered symbol tables. |
tsc/internal/ast/symbol_test.go |
Adapts symbol accessor and ownership tests. |
tsc/internal/api/session.go |
Migrates API symbol-table traversal. |
tsc/internal/api/session_symbolresponse_test.go |
Adapts API member lookup tests. |
Review effort: Balanced
| undo := func() { | ||
| for _, s := range newLocals { | ||
| delete(locals, s) | ||
| locals.Delete(s) |
|
Hey Anders Hejlsberg (@ahejlsberg), the results of running the DT tests are ready. Everything looks the same! |
|
Anders Hejlsberg (@ahejlsberg) Here are the results of running the user tests with tsc comparing Everything looks good! |
|
Anders Hejlsberg (@ahejlsberg) Here they are:
Provisional hosted-runner results: these VMs are not the dedicated benchmark machines. Results may be noisier and are not comparable to the historical series. For comparisons, both revisions of each scenario ran on the same VM. tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

This PR builds on #64916 to further optimize symbol tables. Symbol table entries are now just
*ast.Symbol(half the size of #64916) and the rare renamed symbols are stored via proxy symbols that carry the new name and a reference to the original symbol.Closes #64916