Skip to content

AST nodes as handles, offsets into areanas - #64698

Draft
Jake Bailey (jakebailey) wants to merge 22 commits into
microsoft:mainfrom
jakebailey:arena-ast
Draft

Jake Bailey (jakebailey) wants to merge 22 commits into
microsoft:mainfrom
jakebailey:arena-ast

Conversation

@jakebailey

Copy link
Copy Markdown
Member

WIP, this is unchecked slop

Built on top of #64063

Replace nine nodeData interface methods with generated Kind-switch dispatchers to reduce interface method promotion and itab size.
Replace large sparse Kind switches with byte-indexed dispatch tables
and dense switches, while leaving small switches unchanged. Keep the
concrete calls visible to escape analysis without restoring promoted
interface methods.

Add accessor correctness tests and fixture-based benchmarks covering
both mixed nodes and nodes with populated accessor results.
Index generated accessor tables directly with the node kind. Invalid
kinds now hit the normal Go bounds check rather than returning nil.
Update accessor tests to use valid constructed nodes.
…patch-opt

# Conflicts:
#	tsc/internal/ast/kind_stringer_generated.go
Keep the accessor benchmarks compatible with the rooted path types
and filesystem case sensitivity API now used on main.
The pointer-based AST keeps most of its retained heap visible to the
garbage collector. Source-file-relative handles and pointer-free records
reduce that scan workload and retained memory without changing compiler
or language-service behavior or the JavaScript AST wire format.

The matched workload improves memory use, not navigation CPU time.
Interleaved CPU samples are noisy and navigation remains slower.

Benchstat CSV, generated-method foundation versus arena (six samples):

,baseline,,arena,,,
,sec/op,CI,sec/op,CI,vs base,P
ASTArena/Parse-20,0.0031952075,130%,0.003543635,193%,~,p=0.589 n=6
ASTArena/Navigate-20,7.546e-05,67%,0.000139277,47%,+84.57%,p=0.041 n=6

,baseline,,arena,,,
,B/op,CI,B/op,CI,vs base,P
ASTArena/Parse-20,1.2868065e+06,0%,1.1690025e+06,0%,-9.15%,p=0.002 n=6
ASTArena/Navigate-20,0,0%,0,0%,~,p=1.000 n=6

,baseline,,arena,,,
,allocs/op,CI,allocs/op,CI,vs base,P
ASTArena/Parse-20,153,0%,141,1%,-7.84%,p=0.002 n=6
ASTArena/Navigate-20,0,0%,0,0%,~,p=1.000 n=6

,baseline,,arena,,,
,live-B/file,CI,live-B/file,CI,vs base,P
ASTArenaRetained-20,1.256137e+06,0%,902714.5,0%,-28.14%,p=0.002 n=6

,baseline,,arena,,,
,scan-B/file,CI,scan-B/file,CI,vs base,P
ASTArenaRetained-20,1.2549315e+06,0%,296259.5,0%,-76.39%,p=0.002 n=6

npx hereby validate --all passed with unchanged compiler baselines.
Race/checkptr and 32-bit arena tests passed; the WASI AST tests compile.
@typescript-automation typescript-automation Bot added Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug labels Oct 8, 2026
@jakebailey

Copy link
Copy Markdown
Member Author

TypeScript Bot (@typescript-bot) perf test this

@typescript-automation

typescript-automation Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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

Command Status Results
perf test this ✅ Started

@jakebailey Jake Bailey (jakebailey) changed the title AST arenas AST nodes as handles, offsets into areanas Oct 8, 2026
Storage invariants, compatibility constraints, experiments, and newly
discovered races need to stay with the implementation so subsequent
changes do not repeat the same mistakes. General contributor guidance
is not the right place for branch-specific architectural details.
SourceFile owns mutable metadata and synchronization primitives even
though ordinary AST nodes are value handles. Copying the file for a
field access races with concurrent binding and cache initialization,
including when the requested arena field itself is stable.

The focused regression reproduces the race before the fix. Both exact
race-enabled smoke commands and npx hereby validate --all now pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant