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

Reorganize AST to prevent duplicate fields - #4744

Merged
Jake Bailey (jakebailey) merged 5 commits into
mainfrom
jabaile/fix-ast-extra-embedding
Jul 27, 2026
Merged

Jake Bailey (jakebailey) merged 5 commits into
mainfrom
jabaile/fix-ast-extra-embedding

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Jul 26, 2026 •

Copy link
Copy Markdown
Member

While working on some stuff related to method wrapping, copilot randomly told me that we had accidentally duplicated a bunch of structs in our fun AST embedding layout, including UnionTypeNode, IntersectionTypeNode, FunctionTypeNode, ConstructorTypeNode, FunctionExpression, MethodDeclaration, and GetAccessorDeclaration.

Thankfully, the AST is now generated, so, fixing this is fairly easy and saves memory:

goos: linux
goarch: amd64
pkg: github.com/microsoft/typescript-go/internal/parser
cpu: AMD Ryzen AI 9 HX 370 w/ Radeon 890M           
                                                      │   old.txt    │               new.txt               │
                                                      │    sec/op    │    sec/op     vs base               │
Parse/empty.ts-24                                       399.4n ± 17%   415.8n ± 16%       ~ (p=0.123 n=10)
Parse/checker.ts-24                                     34.11m ±  8%   33.32m ±  5%       ~ (p=0.579 n=10)
Parse/dom.generated.d.ts-24                             13.08m ±  7%   13.49m ±  9%       ~ (p=0.631 n=10)
Parse/Herebyfile.mjs-24                                 509.0µ ±  4%   502.6µ ±  7%       ~ (p=0.436 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx-24   140.2µ ±  6%   136.3µ ±  1%       ~ (p=0.105 n=10)
geomean                                                 417.7µ         418.3µ        +0.13%
                                                      │   old.txt    │                new.txt                │
                                                      │     B/op     │     B/op      vs base                 │
Parse/empty.ts-24                                       1.048Ki ± 0%   1.048Ki ± 0%       ~ (p=1.000 n=10) ¹
Parse/checker.ts-24                                     26.43Mi ± 0%   26.26Mi ± 0%  -0.67% (p=0.000 n=10)
Parse/dom.generated.d.ts-24                             11.08Mi ± 0%   10.81Mi ± 0%  -2.44% (p=0.000 n=10)
Parse/Herebyfile.mjs-24                                 462.5Ki ± 0%   461.2Ki ± 0%  -0.28% (p=0.000 n=10)
Parse/jsxComplexSignatureHasApplicabilityError.tsx-24   175.6Ki ± 0%   171.8Ki ± 0%  -2.15% (p=0.000 n=10)
geomean                                                 482.4Ki        477.0Ki       -1.11%
¹ all samples are equal
                                                      │   old.txt   │               new.txt                │
                                                      │  allocs/op  │  allocs/op   vs base                 │
Parse/empty.ts-24                                        4.000 ± 0%    4.000 ± 0%       ~ (p=1.000 n=10) ¹
Parse/checker.ts-24                                     12.02k ± 0%   12.01k ± 0%  -0.02% (p=0.000 n=10)
Parse/dom.generated.d.ts-24                             2.864k ± 0%   2.862k ± 0%  -0.07% (p=0.000 n=10)
Parse/Herebyfile.mjs-24                                 1.119k ± 0%   1.119k ± 0%       ~ (p=1.000 n=10) ¹
Parse/jsxComplexSignatureHasApplicabilityError.tsx-24    196.0 ± 0%    196.0 ± 0%       ~ (p=1.000 n=10) ¹
geomean                                                  496.6         496.5       -0.02%
¹ all samples are equal

Also, reorder inheritance so that Node is always first in the structs; this was not the case for many!

Copilot AI review requested due to automatic review settings July 26, 2026 00:24
@jakebailey

Copy link
Copy Markdown
Member Author

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

@typescript-automation

typescript-automation Bot commented Jul 26, 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

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

Prevents duplicate embedded AST bases, reducing parser memory usage while preserving TypeScript interface compatibility.

Changes:

  • Restructures declaration and type-node inheritance to eliminate duplicate Go storage.
  • Adds generator validation to reject duplicate base inheritance.
  • Regenerates Go and native-preview TypeScript AST definitions.

Reviewed changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated no comments.

Show a summary per file
File Description
_scripts/ast.json Corrects AST inheritance relationships.
_scripts/generate-go-ast.ts Validates base inheritance uniqueness.
internal/ast/ast_generated.go Applies corrected Go struct layouts.
internal/ast/ast.go Removes obsolete declaration accessors.
_packages/native-preview/src/ast/ast.generated.ts Updates generated TypeScript interfaces.
Files not reviewed (1)
  • internal/ast/ast_generated.go: Generated file
@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 4 4 ~ ~ ~ p=1.000 n=6
Symbols 81,809 (± 0.03%) 81,805 (± 0.03%) ~ 81,778 81,837 p=0.630 n=6
Types 98,817 98,817 ~ ~ ~ p=1.000 n=6
Memory Used 176,128k (± 0.42%) 175,697k (± 0.49%) ~ 174,356k 176,346k p=0.378 n=6
Memory Allocs 2,695,272 (± 0.01%) 2,695,344 (± 0.01%) ~ 2,694,994 2,695,486 p=0.689 n=6
Config Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Parse Time 0.054s (± 5.61%) 0.056s (± 5.48%) ~ 0.053s 0.061s p=0.191 n=6
Bind Time 0.018s (±17.90%) 0.018s (±28.54%) ~ 0.013s 0.027s p=0.518 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.815s (± 1.16%) 0.830s (± 1.26%) +0.015s (+ 1.82%) 0.815s 0.845s p=0.037 n=6
Total Time 0.888s (± 0.60%) 0.905s (± 0.86%) +0.016s (+ 1.82%) 0.897s 0.915s p=0.005 n=6
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 872,459 (± 0.19%) 871,730 (± 0.15%) ~ 869,472 873,201 p=0.378 n=6
Types 263,961 (± 0.00%) 263,962 (± 0.00%) ~ 263,961 263,964 p=0.288 n=6
Memory Used 828,418k (± 0.06%) 825,774k (± 0.12%) -2,644k (- 0.32%) 824,895k 827,178k p=0.005 n=6
Memory Allocs 13,189,069 (± 0.25%) 13,210,043 (± 0.33%) ~ 13,169,033 13,283,869 p=0.575 n=6
Config Time 0.017s 0.019s (±18.80%) ~ 0.017s 0.026s p=0.073 n=6
Parse Time 0.246s (± 3.02%) 0.256s (± 3.08%) ~ 0.246s 0.265s p=0.128 n=6
Bind Time 0.050s (±25.43%) 0.042s (± 3.96%) ~ 0.039s 0.044s p=0.286 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 1.918s (± 1.51%) 1.925s (± 1.73%) ~ 1.865s 1.968s p=0.936 n=6
Total Time 2.242s (± 1.00%) 2.250s (± 1.46%) ~ 2.193s 2.293s p=0.521 n=6
mui-docs - native
Errors 11,273 (± 0.09%) 11,281 (± 0.01%) ~ 11,279 11,282 p=0.102 n=6
Symbols 4,448,802 4,448,802 ~ ~ ~ p=1.000 n=6
Types 1,659,690 1,659,690 ~ ~ ~ p=1.000 n=6
Memory Used 5,074,271k (± 0.05%) 5,068,474k (± 0.04%) -5,797k (- 0.11%) 5,065,312k 5,071,849k p=0.005 n=6
Memory Allocs 51,250,421 (± 0.09%) 51,272,623 (± 0.06%) ~ 51,222,532 51,324,962 p=0.230 n=6
Config Time 0.017s (± 5.07%) 0.017s (±10.73%) ~ 0.016s 0.021s p=0.383 n=6
Parse Time 0.537s (± 1.82%) 0.530s (± 3.34%) ~ 0.502s 0.555s p=0.575 n=6
Bind Time 0.002s 0.002s ~ ~ ~ p=1.000 n=6
Check Time 16.715s (± 0.48%) 16.732s (± 1.01%) ~ 16.569s 16.969s p=0.575 n=6
Emit Time 0.462s (± 3.36%) 0.492s (±12.13%) ~ 0.456s 0.610s p=0.077 n=6
Total Time 18.452s (± 0.56%) 18.547s (± 1.30%) ~ 18.249s 18.816s p=0.575 n=6
self-build-src - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,394,220 1,394,220 ~ ~ ~ p=1.000 n=6
Types 442,210 442,210 ~ ~ ~ p=1.000 n=6
Memory Used 1,657,504k (± 0.30%) 1,647,895k (± 0.55%) ~ 1,639,436k 1,664,601k p=0.066 n=6
Memory Allocs 97,237,722 (± 0.05%) 97,241,131 (± 0.07%) ~ 97,186,588 97,370,969 p=0.936 n=6
Config Time 0.018s (±32.52%) 0.017s (±39.15%) ~ 0.010s 0.026s p=0.748 n=6
Parse Time 0.277s (± 3.24%) 0.272s (± 2.52%) ~ 0.265s 0.283s p=0.298 n=6
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Check Time 2.173s (± 0.91%) 2.187s (± 0.41%) ~ 2.178s 2.201s p=0.066 n=6
Emit Time 0.296s (± 2.32%) 0.301s (± 4.06%) ~ 0.286s 0.319s p=0.689 n=6
Total Time 28.918s (± 1.26%) 29.080s (± 0.86%) ~ 28.847s 29.457s p=0.230 n=6
self-compiler - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 337,681 337,681 ~ ~ ~ p=1.000 n=6
Types 199,559 199,559 ~ ~ ~ p=1.000 n=6
Memory Used 326,544k (± 0.05%) 324,981k (± 0.03%) -1,563k (- 0.48%) 324,869k 325,100k p=0.005 n=6
Memory Allocs 4,685,400 (± 0.01%) 4,685,127 (± 0.01%) ~ 4,684,493 4,685,563 p=0.689 n=6
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Parse Time 0.132s (± 5.27%) 0.126s (± 4.21%) ~ 0.120s 0.134s p=0.126 n=6
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Check Time 1.290s (± 0.94%) 1.287s (± 0.58%) ~ 1.281s 1.301s p=0.687 n=6
Emit Time 0.123s (± 9.49%) 0.119s (± 7.91%) ~ 0.105s 0.130s p=0.936 n=6
Total Time 1.599s (± 1.15%) 1.592s (± 0.41%) ~ 1.581s 1.598s p=0.748 n=6
ts-pre-modules - native
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 97,488 97,488 ~ ~ ~ p=1.000 n=6
Types 356 356 ~ ~ ~ p=1.000 n=6
Memory Used 133,720k (± 0.02%) 132,431k (± 0.01%) -1,289k (- 0.96%) 132,411k 132,459k p=0.005 n=6
Memory Allocs 180,193 (± 0.20%) 180,585 (± 0.34%) ~ 179,784 181,408 p=0.128 n=6
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Parse Time 0.113s (± 4.98%) 0.114s (± 5.29%) ~ 0.106s 0.121s p=0.936 n=6
Bind Time 0.035s (±12.62%) 0.039s (±12.22%) ~ 0.032s 0.046s p=0.127 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Total Time 0.152s (± 2.97%) 0.157s (± 3.51%) ~ 0.150s 0.166s p=0.125 n=6
vscode - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 7,369,594 7,369,594 ~ ~ ~ p=1.000 n=6
Types 2,577,451 2,577,451 ~ ~ ~ p=1.000 n=6
Memory Used 5,043,680k (± 0.03%) 5,035,252k (± 0.03%) -8,428k (- 0.17%) 5,033,554k 5,037,874k p=0.005 n=6
Memory Allocs 37,900,499 (± 0.08%) 37,907,220 (± 0.06%) ~ 37,865,880 37,932,982 p=0.936 n=6
Config Time 0.077s (± 9.27%) 0.074s (± 6.81%) ~ 0.067s 0.080s p=0.470 n=6
Parse Time 0.944s (± 3.19%) 0.933s (± 3.65%) ~ 0.875s 0.976s p=0.521 n=6
Bind Time 0.195s (±35.62%) 0.201s (±30.59%) ~ 0.154s 0.291s p=0.936 n=6
Check Time 8.481s (± 0.95%) 8.487s (± 0.71%) ~ 8.418s 8.555s p=0.575 n=6
Emit Time 2.319s (±10.32%) 2.238s (± 8.64%) ~ 2.019s 2.513s p=0.575 n=6
Total Time 12.037s (± 1.11%) 11.958s (± 0.81%) ~ 11.851s 12.105s p=0.378 n=6
webpack - native
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 193,451 193,451 ~ ~ ~ p=1.000 n=6
Types 340 340 ~ ~ ~ p=1.000 n=6
Memory Used 238,877k (± 0.18%) 236,843k (± 0.04%) -2,034k (- 0.85%) 236,692k 236,947k p=0.005 n=6
Memory Allocs 988,089 (± 0.52%) 987,525 (± 0.26%) ~ 984,219 990,994 p=0.689 n=6
Config Time 0.010s (±16.88%) 0.011s (±23.11%) ~ 0.008s 0.015s p=0.684 n=6
Parse Time 0.158s (± 6.13%) 0.155s (± 3.03%) ~ 0.148s 0.160s p=0.630 n=6
Bind Time 0s 0s ~ ~ ~ p=1.000 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.039s (±15.96%) 0.042s (±13.10%) ~ 0.036s 0.052s p=0.261 n=6
Total Time 0.208s (± 5.33%) 0.208s (± 3.70%) ~ 0.196s 0.219s p=0.809 n=6
xstate-main - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 1,064,618 1,064,618 ~ ~ ~ p=1.000 n=6
Types 392,776 392,776 ~ ~ ~ p=1.000 n=6
Memory Used 649,165k (± 0.03%) 645,587k (± 0.03%) -3,578k (- 0.55%) 645,432k 645,835k p=0.005 n=6
Memory Allocs 5,010,128 (± 0.16%) 5,007,746 (± 0.14%) ~ 4,999,758 5,018,234 p=0.689 n=6
Config Time 0.005s (±17.48%) 0.004s (±18.57%) ~ 0.003s 0.005s p=0.673 n=6
Parse Time 0.135s (± 3.51%) 0.131s (± 3.80%) ~ 0.122s 0.136s p=0.106 n=6
Bind Time 0.036s (±26.13%) 0.036s (±25.28%) ~ 0.024s 0.046s p=0.936 n=6
Check Time 1.233s (± 0.58%) 1.238s (± 0.99%) ~ 1.221s 1.252s p=0.520 n=6
Emit Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Total Time 1.413s (± 0.69%) 1.413s (± 0.52%) ~ 1.401s 1.420s p=1.000 n=6
System info unknown
Hosts
  • native
Scenarios
  • Compiler-Unions - native
  • angular-1 - native
  • mui-docs - native
  • self-build-src - native
  • self-compiler - native
  • ts-pre-modules - native
  • vscode - native
  • webpack - native
  • xstate-main - native
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

Comment thread _scripts/generate-go-ast.ts Resolved
Comment thread _scripts/generate-go-ast.ts Resolved
Co-authored-by: Jake Bailey <5341706+jakebailey@users.noreply.github.com>
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Jul 27, 2026
Merged via the queue into main with commit c3a0059 Jul 27, 2026
21 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the jabaile/fix-ast-extra-embedding branch July 27, 2026 16:57
Jake Bailey (jakebailey) added a commit to jakebailey/TypeScript that referenced this pull request Aug 13, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants