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

Embed zero-size marker bases first in generated AST structs - #4788

Merged
Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
mds-ant:perf/ast-node-layout
Jul 29, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
microsoft:mainfrom
mds-ant:perf/ast-node-layout

Conversation

@mds-ant

Copy link
Copy Markdown
Contributor

Context

AST nodes are arena-allocated, so their struct size is paid in full for every node. #4744 removed the duplicate embedded bases from the generated node structs; one source of padding remains.

The zero-size marker bases (TypeSyntaxBase, TypeElementBase, ClassElementBase, ObjectLiteralElementBase) are embedded in schema order, which can leave one of them as a struct's last field. Go pads a trailing zero-size field so its address stays in bounds, so TypeNodeBase, which ends in TypeSyntaxBase, and every type node built on it carry an extra padding word. The signature declarations, NotEmittedTypeElement and SemicolonClassElement end in a marker as well.

This PR

In this PR, the Go generator embeds zero-size marker bases first. Because a marker occupies no bytes, the base carrying NodeBase still lands at offset zero, so the verifyNodeBaseAtOffsetZero check from #4744 is unaffected. Only internal/ast/ast_generated.go changes (embed order); no fields, accessors or APIs are renamed.

45 node and base structs shrink by 8 bytes.
Struct main this PR
ArrayTypeNode 64 B 56 B
CallSignatureDeclaration 112 B 104 B
ConditionalTypeNode 104 B 96 B
ConstructorTypeNode 120 B 112 B
ConstructSignatureDeclaration 112 B 104 B
FunctionOrConstructorTypeNodeBase 120 B 112 B
FunctionTypeNode 120 B 112 B
ImportTypeNode 96 B 88 B
IndexedAccessTypeNode 72 B 64 B
IndexSignatureDeclaration 120 B 112 B
InferTypeNode 64 B 56 B
IntersectionTypeNode 64 B 56 B
JSDocAllType 56 B 48 B
JSDocNameReference 64 B 56 B
JSDocNonNullableType 64 B 56 B
JSDocNullableType 64 B 56 B
JSDocOptionalType 64 B 56 B
JSDocSignature 112 B 104 B
JSDocTypeBase 56 B 48 B
JSDocTypeExpression 64 B 56 B
JSDocTypeLiteral 96 B 88 B
JSDocVariadicType 64 B 56 B
KeywordTypeNode 56 B 48 B
LiteralTypeNode 64 B 56 B
MappedTypeNode 128 B 120 B
MethodSignatureDeclaration 136 B 128 B
NamedTupleMember 96 B 88 B
NodeWithTypeArgumentsBase 64 B 56 B
NotEmittedTypeElement 56 B 48 B
OptionalTypeNode 64 B 56 B
ParenthesizedTypeNode 64 B 56 B
RestTypeNode 64 B 56 B
SemicolonClassElement 64 B 56 B
TemplateLiteralTypeNode 72 B 64 B
TemplateLiteralTypeSpan 72 B 64 B
ThisTypeNode 56 B 48 B
TupleTypeNode 64 B 56 B
TypeLiteralNode 72 B 64 B
TypeNodeBase 56 B 48 B
TypeOperatorNode 72 B 64 B
TypePredicateNode 80 B 72 B
TypeQueryNode 72 B 64 B
TypeReferenceNode 72 B 64 B
UnionOrIntersectionTypeNodeBase 64 B 56 B
UnionTypeNode 64 B 56 B

Memory

Memory used from --extendedDiagnostics on VS Code src (--noEmit):

Metric Before After Δ
Memory used 4,058.3 MB 4,050.3 MB −8.1 MB

This PR was assisted by Claude Code.

The generator embedded bases in schema order, so a zero-size marker base (`TypeSyntaxBase`, `TypeElementBase`, `ClassElementBase`, `ObjectLiteralElementBase`) could land as a struct's last field, which Go pads. `TypeNodeBase` ended in `TypeSyntaxBase`, so every type node paid for that padding. Marker bases are now embedded first.
Copilot AI review requested due to automatic review settings July 29, 2026 12:28

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

Optimizes AST memory layout by placing zero-size marker bases before non-zero embedded bases.

Changes:

  • Adds generator logic to reorder zero-size bases.
  • Regenerates AST structs with optimized embedding order.

Reviewed changes

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

File Description
_scripts/generate-go-ast.ts Adds zero-size base detection and ordering.
internal/ast/ast_generated.go Applies optimized embedding order to generated structs.
Files not reviewed (1)
  • internal/ast/ast_generated.go: Generated file
Comment thread _scripts/generate-go-ast.ts Resolved
@jakebailey

Copy link
Copy Markdown
Member
@typescript-automation

typescript-automation Bot commented Jul 29, 2026 •

Copy link
Copy Markdown

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

Command Status Results
perf test this ✅ 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 4 4 ~ ~ ~ p=1.000 n=6
Symbols 81,801 (± 0.01%) 81,797 (± 0.01%) ~ 81,786 81,810 p=0.471 n=6
Types 98,817 98,817 ~ ~ ~ p=1.000 n=6
Memory Used 173,798k (± 0.17%) 173,996k (± 0.43%) ~ 172,923k 175,111k p=0.575 n=6
Memory Allocs 2,694,745 (± 0.01%) 2,694,625 (± 0.01%) ~ 2,694,436 2,694,875 p=0.471 n=6
Config Time 0.000s (±244.70%) 0.000s ~ ~ ~ p=0.405 n=6
Parse Time 0.058s (± 9.73%) 0.056s (± 9.36%) ~ 0.051s 0.063s p=0.686 n=6
Bind Time 0.018s (±24.09%) 0.020s (±28.21%) ~ 0.013s 0.028s p=0.810 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.818s (± 1.43%) 0.810s (± 0.84%) ~ 0.801s 0.821s p=0.297 n=6
Total Time 0.896s (± 0.71%) 0.888s (± 1.52%) ~ 0.874s 0.905s p=0.470 n=6
angular-1 - native
Errors 3 3 ~ ~ ~ p=1.000 n=6
Symbols 871,791 (± 0.15%) 872,239 (± 0.06%) ~ 871,477 872,834 p=0.575 n=6
Types 263,961 (± 0.00%) 263,962 (± 0.00%) ~ 263,960 263,963 p=0.601 n=6
Memory Used 813,194k (± 0.09%) 809,213k (± 0.06%) -3,982k (- 0.49%) 808,628k 809,660k p=0.005 n=6
Memory Allocs 13,143,643 (± 0.11%) 13,153,431 (± 0.18%) ~ 13,132,139 13,192,275 p=0.471 n=6
Config Time 0.018s (± 4.78%) 0.017s (± 4.38%) ~ 0.016s 0.018s p=0.652 n=6
Parse Time 0.229s (± 3.79%) 0.234s (± 6.42%) ~ 0.203s 0.241s p=0.226 n=6
Bind Time 0.045s (±20.30%) 0.049s (±39.15%) ~ 0.039s 0.088s p=1.000 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 1.886s (± 0.94%) 1.901s (± 1.67%) ~ 1.864s 1.944s p=0.575 n=6
Total Time 2.189s (± 0.92%) 2.209s (± 1.32%) ~ 2.179s 2.250s p=0.298 n=6
mui-docs - native
Errors 11,277 (± 0.07%) 11,278 (± 0.07%) ~ 11,263 11,282 p=0.867 n=6
Symbols 4,384,004 4,384,004 ~ ~ ~ p=1.000 n=6
Types 1,536,962 1,536,962 ~ ~ ~ p=1.000 n=6
Memory Used 4,964,159k (± 0.02%) 4,959,585k (± 0.03%) -4,574k (- 0.09%) 4,958,553k 4,961,984k p=0.005 n=6
Memory Allocs 45,999,655 (± 0.04%) 45,999,632 (± 0.09%) ~ 45,959,523 46,064,412 p=0.936 n=6
Config Time 0.028s (±15.60%) 0.026s (±14.14%) ~ 0.022s 0.031s p=0.520 n=6
Parse Time 0.556s (± 1.58%) 0.554s (± 2.63%) ~ 0.537s 0.569s p=1.000 n=6
Bind Time 0.003s (±19.35%) 0.003s (±19.35%) ~ 0.002s 0.003s p=1.000 n=6
Check Time 18.846s (± 0.38%) 18.859s (± 0.31%) ~ 18.763s 18.912s p=0.689 n=6
Emit Time 0.550s (± 5.40%) 0.549s (± 4.85%) ~ 0.530s 0.584s p=0.808 n=6
Total Time 20.824s (± 0.65%) 20.850s (± 0.26%) ~ 20.771s 20.915s p=1.000 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,612,300k (± 0.28%) 1,598,885k (± 0.35%) -13,415k (- 0.83%) 1,592,291k 1,607,721k p=0.008 n=6
Memory Allocs 97,118,868 (± 0.05%) 97,096,399 (± 0.08%) ~ 97,011,955 97,240,384 p=0.471 n=6
Config Time 0.023s (± 8.03%) 0.022s (±17.47%) ~ 0.016s 0.028s p=0.870 n=6
Parse Time 0.240s (± 2.67%) 0.233s (± 2.89%) ~ 0.227s 0.245s p=0.108 n=6
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Check Time 2.546s (± 0.70%) 2.539s (± 1.13%) ~ 2.490s 2.572s p=0.936 n=6
Emit Time 0.349s (± 4.71%) 0.352s (± 4.38%) ~ 0.338s 0.377s p=1.000 n=6
Total Time 32.561s (± 1.17%) 32.490s (± 0.65%) ~ 32.258s 32.773s p=0.378 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 320,608k (± 0.02%) 319,388k (± 0.05%) -1,220k (- 0.38%) 319,144k 319,533k p=0.005 n=6
Memory Allocs 4,676,394 (± 0.02%) 4,676,135 (± 0.02%) ~ 4,674,762 4,677,374 p=0.689 n=6
Config Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Parse Time 0.116s (± 2.70%) 0.116s (± 2.64%) ~ 0.112s 0.120s p=0.872 n=6
Bind Time 0.000s 0.000s ~ ~ ~ p=1.000 n=6
Check Time 1.280s (± 1.04%) 1.287s (± 1.60%) ~ 1.268s 1.322s p=0.748 n=6
Emit Time 0.117s (± 7.58%) 0.110s (± 5.29%) ~ 0.103s 0.117s p=0.125 n=6
Total Time 1.565s (± 0.99%) 1.569s (± 1.65%) ~ 1.549s 1.617s p=0.936 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 128,895k (± 0.01%) 127,897k (± 0.02%) -998k (- 0.77%) 127,879k 127,952k p=0.005 n=6
Memory Allocs 177,502 (± 0.12%) 177,374 (± 0.18%) ~ 177,096 177,907 p=0.378 n=6
Config Time 0.001s (±48.94%) 0.001s ~ ~ ~ p=0.405 n=6
Parse Time 0.107s (± 6.72%) 0.101s (± 2.04%) ~ 0.100s 0.105s p=0.288 n=6
Bind Time 0.041s (±11.72%) 0.038s (±17.24%) ~ 0.029s 0.048s p=0.261 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.151s (± 6.37%) 0.143s (± 4.15%) ~ 0.136s 0.153s p=0.108 n=6
vscode - native
Errors 0 0 ~ ~ ~ p=1.000 n=6
Symbols 7,499,780 7,499,780 ~ ~ ~ p=1.000 n=6
Types 2,616,632 2,616,632 ~ ~ ~ p=1.000 n=6
Memory Used 5,049,191k (± 0.03%) 5,040,502k (± 0.03%) -8,690k (- 0.17%) 5,038,770k 5,042,665k p=0.005 n=6
Memory Allocs 38,218,005 (± 0.04%) 38,230,084 (± 0.04%) ~ 38,214,915 38,251,684 p=0.173 n=6
Config Time 0.076s (± 8.90%) 0.077s (± 3.53%) ~ 0.075s 0.082s p=0.810 n=6
Parse Time 0.939s (± 1.67%) 0.896s (± 4.21%) ~ 0.849s 0.945s p=0.090 n=6
Bind Time 0.167s (± 5.64%) 0.204s (±35.56%) ~ 0.159s 0.347s p=0.297 n=6
Check Time 8.490s (± 1.05%) 8.563s (± 1.20%) ~ 8.435s 8.661s p=0.297 n=6
Emit Time 2.479s (± 8.87%) 2.273s (±12.12%) ~ 2.079s 2.638s p=0.575 n=6
Total Time 12.172s (± 1.21%) 12.034s (± 1.42%) ~ 11.898s 12.272s p=0.066 n=6
webpack - native
Errors 2 2 ~ ~ ~ p=1.000 n=6
Symbols 193,872 193,872 ~ ~ ~ p=1.000 n=6
Types 340 340 ~ ~ ~ p=1.000 n=6
Memory Used 230,439k (± 0.12%) 227,947k (± 0.20%) -2,492k (- 1.08%) 227,232k 228,295k p=0.005 n=6
Memory Allocs 973,101 (± 0.60%) 973,979 (± 0.62%) ~ 966,121 980,357 p=0.689 n=6
Config Time 0.011s (±16.92%) 0.013s (±16.91%) ~ 0.010s 0.016s p=0.119 n=6
Parse Time 0.149s (± 5.12%) 0.146s (± 3.60%) ~ 0.138s 0.151s p=0.810 n=6
Bind Time 0s 0s ~ ~ ~ p=1.000 n=6
Check Time 0s 0s ~ ~ ~ p=1.000 n=6
Emit Time 0.045s (±20.15%) 0.050s (±21.50%) ~ 0.036s 0.063s p=0.575 n=6
Total Time 0.205s (± 6.65%) 0.210s (± 4.07%) ~ 0.199s 0.220s p=0.377 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 637,863k (± 0.02%) 634,486k (± 0.01%) -3,377k (- 0.53%) 634,408k 634,660k p=0.005 n=6
Memory Allocs 4,989,919 (± 0.05%) 4,988,270 (± 0.08%) ~ 4,981,991 4,995,006 p=0.378 n=6
Config Time 0.005s (±17.48%) 0.005s ~ ~ ~ p=0.405 n=6
Parse Time 0.126s (± 4.20%) 0.125s (± 3.20%) ~ 0.119s 0.129s p=1.000 n=6
Bind Time 0.039s (±27.59%) 0.028s (±23.03%) ~ 0.023s 0.040s p=0.106 n=6
Check Time 1.240s (± 0.81%) 1.241s (± 0.53%) ~ 1.235s 1.252s p=0.936 n=6
Emit Time 0.001s 0.001s ~ ~ ~ p=1.000 n=6
Total Time 1.414s (± 0.87%) 1.404s (± 0.58%) ~ 1.394s 1.417s p=0.173 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

lsp

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
Compiler-UnionsLSP - native
Req 1 - updateOpen 10ms (± 4.15%) 11ms (± 5.21%) ~ 10ms 11ms p=0.054 n=6
Req 2 - geterr 871ms (± 0.70%) 876ms (± 0.53%) ~ 868ms 880ms p=0.170 n=6
Req 3 - references 44ms (±13.21%) 44ms (± 9.05%) ~ 40ms 49ms p=0.809 n=6
Req 4 - navto 19ms (±22.37%) 17ms (± 2.38%) ~ 17ms 18ms p=0.863 n=6
Req 5 - completionInfo count 1,357 1,357 ~ ~ ~ p=1.000 n=6
Req 5 - completionInfo 14ms (±14.40%) 15ms (±16.73%) ~ 11ms 17ms p=0.809 n=6
CompilerLSP - native
Req 1 - updateOpen 11ms 11ms (± 5.21%) ~ 10ms 11ms p=0.071 n=6
Req 2 - geterr 441ms (± 2.89%) 437ms (± 2.31%) ~ 426ms 455ms p=0.748 n=6
Req 3 - references 49ms (± 8.75%) 48ms (±10.66%) ~ 41ms 56ms p=0.573 n=6
Req 4 - navto 18ms (± 8.60%) 19ms (±17.57%) ~ 17ms 26ms p=0.383 n=6
Req 5 - completionInfo count 1,519 1,519 ~ ~ ~ p=1.000 n=6
Req 5 - completionInfo 20ms (±19.45%) 20ms (±19.22%) ~ 15ms 26ms p=1.000 n=6
System info unknown
Hosts
  • native
Scenarios
  • CompilerLSP - native
  • Compiler-UnionsLSP - native
  • xstate-main-1-LSP - native
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

startup

Comparison Report - baseline..pr
Metric baseline pr Delta Best Worst p-value
lsp-startup - native
Execution time 5.90ms (±516.55%) 5.90ms (±516.54%) +0.01ms (+ 0.16%) 0.00ms 592.74ms p=0.000 n=600
tsgo-startup - native
Execution time 5.84ms (±516.54%) 5.85ms (±516.54%) +0.01ms (+ 0.16%) 0.00ms 589.05ms p=0.030 n=600
System info unknown
Hosts
  • native
Scenarios
  • lsp-startup - native
  • tsgo-startup - native
Benchmark Name Iterations
Current pr 6
Baseline baseline 6

Developer Information:

Download Benchmarks

@jakebailey Jake Bailey (jakebailey) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this is fine. I do also wonder if we should bother generating them at all, but that comes down to how we plan to use these markers in Go in the future (which I think we do have a plan for). Perhaps we won't physically need them later, then.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Jul 29, 2026
Merged via the queue into microsoft:main with commit 19d61fc Jul 29, 2026
21 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

3 participants