This repository was archived by the owner on Sep 1, 2026. It is now read-only.
Repository navigation
Embed zero-size marker bases first in generated AST structs - #4788
Merged
Jake Bailey (jakebailey) merged 1 commit intoJul 29, 2026
Merged
Conversation
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.
Contributor
There was a problem hiding this comment.
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
Member
|
TypeScript Bot (@typescript-bot) perf test this |
|
Jake Bailey (@jakebailey) Here they are:
tscComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
lspComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
startupComparison Report - baseline..pr
System info unknown
Hosts
Scenarios
Developer Information: |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Jake Bailey (jakebailey)
approved these changes
Jul 29, 2026
Jake Bailey (jakebailey)
left a comment
Member
There was a problem hiding this comment.
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.
Jake Bailey (jakebailey)
pushed a commit
to jakebailey/TypeScript
that referenced
this pull request
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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, soTypeNodeBase, which ends inTypeSyntaxBase, and every type node built on it carry an extra padding word. The signature declarations,NotEmittedTypeElementandSemicolonClassElementend 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
NodeBasestill lands at offset zero, so theverifyNodeBaseAtOffsetZerocheck from #4744 is unaffected. Onlyinternal/ast/ast_generated.gochanges (embed order); no fields, accessors or APIs are renamed.45 node and base structs shrink by 8 bytes.
ArrayTypeNodeCallSignatureDeclarationConditionalTypeNodeConstructorTypeNodeConstructSignatureDeclarationFunctionOrConstructorTypeNodeBaseFunctionTypeNodeImportTypeNodeIndexedAccessTypeNodeIndexSignatureDeclarationInferTypeNodeIntersectionTypeNodeJSDocAllTypeJSDocNameReferenceJSDocNonNullableTypeJSDocNullableTypeJSDocOptionalTypeJSDocSignatureJSDocTypeBaseJSDocTypeExpressionJSDocTypeLiteralJSDocVariadicTypeKeywordTypeNodeLiteralTypeNodeMappedTypeNodeMethodSignatureDeclarationNamedTupleMemberNodeWithTypeArgumentsBaseNotEmittedTypeElementOptionalTypeNodeParenthesizedTypeNodeRestTypeNodeSemicolonClassElementTemplateLiteralTypeNodeTemplateLiteralTypeSpanThisTypeNodeTupleTypeNodeTypeLiteralNodeTypeNodeBaseTypeOperatorNodeTypePredicateNodeTypeQueryNodeTypeReferenceNodeUnionOrIntersectionTypeNodeBaseUnionTypeNodeMemory
Memory usedfrom--extendedDiagnosticson VS Codesrc(--noEmit):This PR was assisted by Claude Code.