Skip to content

Replace nodeData interface with generated AST accessors - #64773

Merged
Jake Bailey (jakebailey) merged 1 commit into
mainfrom
jakebailey/mem/generated-ast-accessors
Oct 14, 2026
Merged

Jake Bailey (jakebailey) merged 1 commit into
mainfrom
jakebailey/mem/generated-ast-accessors

Conversation

@jakebailey

@jakebailey Jake Bailey (jakebailey) commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

This ditches the dynamic dispatch with nodeData in favor of generated kind switches, like I did with ForEachChild.

Metric Merge base Branch Change
Binary file 24,658,183 B 23,810,311 B -847,872 B (-3.44%)
Executable .text 9,491,153 B 9,366,833 B -124,320 B (-1.31%)
Go PC/line metadata .gopclntab 9,280,667 B 8,583,938 B -696,729 B (-7.51%)
Go type metadata .go.type 3,447,248 B 3,404,384 B -42,864 B (-1.24%)
Symbols containing tsc/internal/ast 6,331 2,682 -3,649 (-57.64%)
AST pointer-receiver methods 5,477 1,819 -3,658 (-66.79%)

It also makes compiling the ast package 5% faster. Some dispatch goes through small generated tables, because the fully switch-based code is slower.

Supersedes #64063. Part of the memory optimization stack summarized in #64734.

Dynamic interface dispatch obscures the concrete AST layout and adds
indirection to frequently used compiler accessors. Generated kind-based
dispatch keeps those access paths explicit and checked against the node
schema.

Keep the method-generation foundation together so it can be reviewed or
removed independently of the subsequent storage optimizations.
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 13, 2026
@jakebailey Jake Bailey (jakebailey) changed the title Replace nodeData interface with generated AST accessors Oct 13, 2026
@jakebailey Jake Bailey (jakebailey) changed the title Replace nodeData interface with generated AST accessors This ditches the dynamic dispatch with nodeData in favor of generated kind switches, like I did with ForEachChild. | Metric | Merge base | Branch | Change | |---|---:|---:|---:| | Binary file | 24,658,183 B | 23,810,311 B | **-847,872 B (-3.44%)** | | Executable .text | 9,491,153 B | 9,366,833 B | **-124,320 B (-1.31%)** | | Go PC/line metadata .gopclntab | 9,280,667 B | 8,583,938 B | **-696,729 B (-7.51%)** | | Go type metadata .go.type | 3,447,248 B | 3,404,384 B | **-42,864 B (-1.24%)** | | Symbols containing tsc/internal/ast | 6,331 | 2,682 | **-3,649 (-57.64%)** | | AST pointer-receiver methods | 5,477 | 1,819 | **-3,658 (-66.79%)** | It also makes compiling the ast package 5% faster. Some dispatch goes through small generated tables, because the fully switch-based code is slower. Oct 13, 2026
@jakebailey
Jake Bailey (jakebailey) marked this pull request as ready for review October 13, 2026 17:41
Copilot AI balanced review requested due to automatic review settings October 13, 2026 17:41

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.

🔵 Needs a closer look

It broadly changes core AST construction and dispatch across every compiler node kind, warranting final human validation.

0 open findings

What changed in this PR

Replaces nodeData interface dispatch with generated, kind-based AST accessors to reduce compiler size and improve performance.

Changes:

  • Generates AST traversal, cloning, subtree-fact, and shared accessor dispatch.
  • Adds private kinds for synthetic flow-data nodes.
  • Adds accessor tests and benchmarks.
File Description
tsc/​internal/​ast/​ast.go Removes nodeData and updates node construction.
tsc/​internal/​ast/​ast_generated.go Adds generated kind-based dispatch and constructors.
tsc/​internal/​ast/​flow.go Assigns distinct kinds to synthetic flow data.
tsc/​internal/​ast/​kind_stringer_generated.go Includes synthetic flow kinds in stringification.
tsc/​internal/​ast/​nodeaccessors_test.go Tests accessor behavior and shared kinds.
tsc/​internal/​ast/​nodeaccessors_bench_test.go Benchmarks common accessor paths.
tools/​scripts/​tsc/​generate-go-ast.ts Generates the new dispatch implementation.
Files not reviewed (1)
  • tsc/internal/ast/kind_stringer_generated.go: Generated file

🧠 Review effort: Balanced


💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Oct 14, 2026
@jakebailey
Jake Bailey (jakebailey) removed this pull request from the merge queue due to a manual request Oct 14, 2026
@jakebailey
Jake Bailey (jakebailey) added this pull request to the merge queue Oct 14, 2026
Merged via the queue into main with commit 67a1c76 Oct 14, 2026
30 checks passed
@jakebailey
Jake Bailey (jakebailey) deleted the jakebailey/mem/generated-ast-accessors branch October 14, 2026 01:07
@jakebailey Jake Bailey (jakebailey) added the Domain: Performance Performance related label Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team Domain: Performance Performance related For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

3 participants