Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Cache alias candidates for symbol accessibility - #4102

Closed
Zzzen (Zzzen) wants to merge 1 commit into
microsoft:mainfrom
Zzzen:cache-symbol-accessibility-alias-candidates
Closed

Zzzen (Zzzen) wants to merge 1 commit into
microsoft:mainfrom
Zzzen:cache-symbol-accessibility-alias-candidates

Conversation

@Zzzen

Copy link
Copy Markdown
Contributor

Copilot AI review requested due to automatic review settings May 30, 2026 14:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR optimizes alias resolution by caching exported-symbol alias candidates per container and per resolved/merged target symbol, reducing repeated scans and redundant sorting.

Changes:

  • Added a Checker-level cache mapping containers to exported-target → candidate-export symbols.
  • Updated getAliasForSymbolInContainer to populate and consult the cache.
  • Avoided unnecessary sorting when there is only a single candidate.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
internal/checker/symbolaccessibility.go Adds cached lookup/build path for alias candidates keyed by resolved exported target symbols.
internal/checker/checker.go Introduces a new Checker field to store the alias-candidate cache.

Comment on lines +361 to +382
target := c.getMergedSymbol(c.resolveSymbol(c.getMergedSymbol(symbol)))
if c.aliasCandidatesByExportedTarget != nil {
if candidatesByTarget, ok := c.aliasCandidatesByExportedTarget[container]; ok {
candidates := candidatesByTarget[target]
if len(candidates) > 0 {
if len(candidates) > 1 {
c.sortSymbols(candidates) // _must_ sort exports for stable results - symbol table is randomly iterated
}
return candidates[0]
}
return nil
}
} else {
c.aliasCandidatesByExportedTarget = make(map[*ast.Symbol]map[*ast.Symbol][]*ast.Symbol)
}

candidatesByTarget := make(map[*ast.Symbol][]*ast.Symbol, len(exports))
for _, exported := range exports {
exportedTarget := c.getMergedSymbol(c.resolveSymbol(c.getMergedSymbol(exported)))
candidatesByTarget[exportedTarget] = append(candidatesByTarget[exportedTarget], exported)
}
c.aliasCandidatesByExportedTarget[container] = candidatesByTarget
if c.getSymbolIfSameReference(exported, symbol) != nil {
candidates = append(candidates, exported)

target := c.getMergedSymbol(c.resolveSymbol(c.getMergedSymbol(symbol)))

candidatesByTarget := make(map[*ast.Symbol][]*ast.Symbol, len(exports))
for _, exported := range exports {
exportedTarget := c.getMergedSymbol(c.resolveSymbol(c.getMergedSymbol(exported)))
@jakebailey

Copy link
Copy Markdown
Member

TypeScript Bot (@typescript-bot) perf test this faster

@typescript-automation

typescript-automation Bot commented Aug 14, 2026 •

Copy link
Copy Markdown

Starting jobs; this comment will be updated as builds start and complete.

Command Status Results
perf test this faster ✅ Started 👀 Results

@typescript-automation

Copy link
Copy Markdown

Jake Bailey (@jakebailey)
The results of the perf run you requested are in!

Here they are:

tsc

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-Unions - native
Errors 41 41 ~ ~ ~ p=1.000 n=12
Symbols 115,480 115,480 ~ ~ ~ p=1.000 n=12
Types 96,945 96,945 ~ ~ ~ p=1.000 n=12
Memory Used 148,979k (± 0.44%) 149,154k (± 0.51%) ~ 147,798k 151,424k p=0.887 n=12
Memory Allocs 2,247,391 (± 0.00%) 2,247,423 (± 0.01%) ~ 2,247,169 2,247,870 p=0.799 n=12
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Parse Time 0.041s (± 3.34%) 0.041s (± 4.73%) ~ 0.038s 0.047s p=0.696 n=12
Bind Time 0.012s (± 9.53%) 0.013s (±11.31%) ~ 0.010s 0.017s p=0.538 n=12
Check Time 0.507s (± 0.66%) 0.509s (± 0.96%) ~ 0.500s 0.526s p=0.943 n=12
Emit Time 0.271s (± 1.76%) 0.272s (± 2.75%) ~ 0.257s 0.296s p=0.921 n=12
Total Time 0.838s (± 0.75%) 0.842s (± 1.13%) ~ 0.819s 0.859s p=0.580 n=12
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=12
Symbols 847,359 (± 0.08%) 847,037 (± 0.07%) ~ 845,770 848,261 p=0.478 n=12
Types 249,912 (± 0.00%) 249,915 (± 0.00%) ~ 249,912 249,925 p=0.159 n=12
Memory Used 793,100k (± 0.05%) 801,222k (± 0.10%) +8,122k (+ 1.02%) 799,777k 803,565k p=0.000 n=12
Memory Allocs 13,038,162 (± 0.03%) 13,146,562 (± 0.06%) +108,400 (+ 0.83%) 13,140,002 13,184,688 p=0.000 n=12
Config Time 0.016s (± 1.13%) 0.016s (± 1.90%) ~ 0.016s 0.017s p=0.317 n=12
Parse Time 0.281s (± 2.28%) 0.276s (± 2.58%) ~ 0.253s 0.291s p=0.297 n=12
Bind Time 0.064s (±11.28%) 0.065s (±17.07%) ~ 0.057s 0.119s p=0.828 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 1.646s (± 0.93%) 1.644s (± 1.20%) ~ 1.604s 1.720s p=0.629 n=12
Total Time 2.028s (± 1.25%) 2.017s (± 1.35%) ~ 1.955s 2.112s p=0.183 n=12
mui-docs - native
Errors 11,274 (± 0.05%) 11,277 (± 0.03%) ~ 11,267 11,282 p=0.189 n=12
Symbols 4,230,792 4,230,792 ~ ~ ~ p=1.000 n=12
Types 1,591,020 1,591,020 ~ ~ ~ p=1.000 n=12
Memory Used 4,854,826k (± 0.04%) 4,854,050k (± 0.02%) ~ 4,850,807k 4,857,143k p=0.590 n=12
Memory Allocs 48,408,458 (± 0.03%) 48,408,306 (± 0.02%) ~ 48,371,758 48,429,555 p=0.755 n=12
Config Time 0.016s (± 1.81%) 0.016s (± 1.14%) ~ 0.015s 0.016s p=0.590 n=12
Parse Time 0.557s (± 1.33%) 0.547s (± 2.74%) ~ 0.499s 0.575s p=0.385 n=12
Bind Time 0.002s 0.002s (± 8.72%) ~ 0.002s 0.003s p=1.000 n=12
Check Time 15.456s (± 0.57%) 15.519s (± 0.58%) ~ 15.327s 15.712s p=0.487 n=12
Emit Time 0.435s (± 0.36%) 0.437s (± 0.30%) ~ 0.433s 0.439s p=0.242 n=12
Total Time 17.172s (± 0.69%) 17.252s (± 0.63%) ~ 17.017s 17.467s p=0.347 n=12
strada-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,394,411 1,394,411 ~ ~ ~ p=1.000 n=12
Types 443,627 443,627 ~ ~ ~ p=1.000 n=12
Memory Used 1,647,832k (± 0.33%) 1,639,496k (± 0.30%) -8,336k (- 0.51%) 1,623,641k 1,653,661k p=0.024 n=12
Memory Allocs 96,923,749 (± 0.04%) 96,889,499 (± 0.04%) ~ 96,779,090 97,014,577 p=0.198 n=12
Config Time 0.004s (±14.34%) 0.003s (±14.59%) ~ 0.002s 0.004s p=0.583 n=12
Parse Time 0.194s (± 2.40%) 0.195s (± 2.15%) ~ 0.186s 0.206s p=0.898 n=12
Bind Time 0.000s (±217.90%) 0.000s ~ ~ ~ p=1.000 n=12
Check Time 1.831s (± 0.67%) 1.835s (± 0.38%) ~ 1.817s 1.851s p=0.580 n=12
Emit Time 0.305s (± 4.80%) 0.295s (± 4.09%) ~ 0.259s 0.318s p=0.340 n=12
Total Time 25.300s (± 0.71%) 25.163s (± 0.50%) ~ 24.884s 25.570s p=0.198 n=12
strada-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 337,618 337,618 ~ ~ ~ p=1.000 n=12
Types 198,941 198,941 ~ ~ ~ p=1.000 n=12
Memory Used 319,623k (± 0.03%) 319,671k (± 0.06%) ~ 319,360k 320,467k p=0.944 n=12
Memory Allocs 4,661,058 (± 0.01%) 4,660,753 (± 0.01%) ~ 4,659,676 4,662,004 p=0.160 n=12
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=12
Parse Time 0.116s (± 4.04%) 0.117s (± 4.59%) ~ 0.105s 0.135s p=0.842 n=12
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Check Time 1.059s (± 0.55%) 1.062s (± 0.50%) ~ 1.047s 1.077s p=0.163 n=12
Emit Time 0.161s (± 9.43%) 0.163s (± 4.02%) ~ 0.141s 0.177s p=0.599 n=12
Total Time 1.392s (± 1.32%) 1.394s (± 0.62%) ~ 1.378s 1.411s p=0.977 n=12
ts-pre-modules - native
Errors 87 87 ~ ~ ~ p=1.000 n=12
Symbols 305,341 305,341 ~ ~ ~ p=1.000 n=12
Types 182,038 182,038 ~ ~ ~ p=1.000 n=12
Memory Used 277,299k (± 0.01%) 277,282k (± 0.02%) ~ 277,071k 277,399k p=0.965 n=12
Memory Allocs 1,628,072 (± 0.01%) 1,628,086 (± 0.01%) ~ 1,627,695 1,628,412 p=0.755 n=12
Config Time 0.000s (±217.90%) 0.000s (±146.91%) ~ 0.000s 0.001s p=1.000 n=12
Parse Time 0.101s (± 3.60%) 0.099s (± 4.41%) ~ 0.087s 0.107s p=0.599 n=12
Bind Time 0.038s (±11.94%) 0.039s (±10.32%) ~ 0.031s 0.047s p=0.920 n=12
Check Time 0.844s (± 0.61%) 0.842s (± 0.69%) ~ 0.827s 0.857s p=0.809 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.998s (± 0.66%) 0.994s (± 0.58%) ~ 0.979s 1.007s p=0.259 n=12
vscode - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 7,733,268 7,733,268 ~ ~ ~ p=1.000 n=12
Types 2,660,597 2,660,597 ~ ~ ~ p=1.000 n=12
Memory Used 5,225,508k (± 0.01%) 5,226,670k (± 0.01%) +1,162k (+ 0.02%) 5,224,155k 5,228,154k p=0.017 n=12
Memory Allocs 40,486,174 (± 0.03%) 40,493,869 (± 0.02%) +7,695 (+ 0.02%) 40,478,459 40,525,639 p=0.020 n=12
Config Time 0.061s (± 0.53%) 0.061s (± 0.77%) ~ 0.060s 0.062s p=0.433 n=12
Parse Time 1.600s (± 1.05%) 1.601s (± 2.14%) ~ 1.474s 1.664s p=0.505 n=12
Bind Time 0.329s (± 0.43%) 0.352s (±13.64%) ~ 0.328s 0.594s p=0.184 n=12
Check Time 9.844s (± 0.25%) 9.769s (± 1.10%) ~ 9.312s 9.885s p=0.370 n=12
Emit Time 2.961s (± 0.86%) 3.104s (±10.14%) ~ 2.911s 4.689s p=0.876 n=12
Total Time 14.874s (± 0.29%) 14.968s (± 1.71%) ~ 14.661s 16.236s p=0.744 n=12
webpack - native
Errors 2 2 ~ ~ ~ p=1.000 n=12
Symbols 1,380 1,380 ~ ~ ~ p=1.000 n=12
Types 340 340 ~ ~ ~ p=1.000 n=12
Memory Used 194,548k (± 0.07%) 194,545k (± 0.05%) ~ 194,279k 194,810k p=0.932 n=12
Memory Allocs 822,915 (± 0.11%) 822,735 (± 0.14%) ~ 821,473 827,688 p=0.514 n=12
Config Time 0.008s 0.008s ~ ~ ~ p=1.000 n=12
Parse Time 0.205s (± 1.82%) 0.201s (± 2.74%) ~ 0.185s 0.214s p=0.235 n=12
Bind Time 0s 0s ~ ~ ~ p=1.000 n=12
Check Time 0s 0s ~ ~ ~ p=1.000 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 0.213s (± 1.67%) 0.209s (± 2.64%) ~ 0.193s 0.222s p=0.260 n=12
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=12
Symbols 1,020,005 1,020,005 ~ ~ ~ p=1.000 n=12
Types 376,891 376,891 ~ ~ ~ p=1.000 n=12
Memory Used 603,428k (± 0.02%) 603,505k (± 0.01%) ~ 603,343k 603,706k p=0.370 n=12
Memory Allocs 4,748,886 (± 0.03%) 4,750,217 (± 0.03%) ~ 4,746,931 4,754,420 p=0.219 n=12
Config Time 0.003s (± 6.23%) 0.003s ~ ~ ~ p=1.000 n=12
Parse Time 0.147s (± 3.25%) 0.145s (± 2.55%) ~ 0.133s 0.155s p=0.433 n=12
Bind Time 0.046s (±17.01%) 0.045s (±19.17%) ~ 0.032s 0.071s p=0.579 n=12
Check Time 1.094s (± 0.87%) 1.093s (± 0.75%) ~ 1.070s 1.113s p=0.832 n=12
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=12
Total Time 1.302s (± 0.89%) 1.298s (± 0.77%) ~ 1.267s 1.317s p=0.400 n=12
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • mui-docs - native
  • strada-build-src - native
  • strada-compiler - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 12
Baseline baseline 12

Developer Information:

Download Benchmarks

@RyanCavanaugh Ryan Cavanaugh (RyanCavanaugh) added the Unmigrated PR This PR was open at the time of the repo move back to TypeScript label Aug 19, 2026
@RyanCavanaugh

Copy link
Copy Markdown
Member

Thank you for contributing to the TypeScript native port!

Development has moved from this repository back to the main microsoft/TypeScript repository. GitHub does not have PR transfer functionality, so we're closing this PR here.

If this change is still relevant, please reopen it as a new pull request in microsoft/TypeScript. We'd appreciate your help carrying the contribution over, and we apologize for the extra work.

See microsoft/typescript-go#4918 for more information about the move.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Unmigrated PR This PR was open at the time of the repo move back to TypeScript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Declaration emit spends significant CPU in getAliasForSymbolInContainer / getAlternativeContainingModules

4 participants