Skip to main content

Module node

Module node 

Source
Expand description

Thin Node Architecture for Cache-Efficient AST

This module implements a cache-optimized AST representation where each node is exactly 16 bytes (4 nodes per 64-byte cache line), compared to the previous 208-byte Node enum (0.31 nodes per cache line).

§Architecture

Instead of a single large enum, we use:

  1. Node - A 16-byte header containing kind, flags, position, and a data index
  2. Typed storage pools - Separate Vec for each node category

The data_index field points into the appropriate pool based on kind.

§Performance Impact

  • Before: 208 bytes/node = 0.31 nodes/cache-line
  • After: 16 bytes/node = 4 nodes/cache-line
  • Improvement: 13x better cache locality for AST traversal

§Design Principles

  1. Common data inline: kind, flags, pos, end are accessed constantly
  2. Rare data indirect: modifiers, type parameters, etc. via index
  3. No heap allocation per node: All storage in arena vectors
  4. O(1) node access: Direct index into typed pool

Structs§

AccessExprData
Data for property/element access
AccessorData
Data for accessor declarations (get/set)
ArrayTypeData
Data for array type
BinaryExprData
Data for binary expressions
BindingElementData
Data for binding elements
BindingPatternData
Data for binding patterns
BlockData
Data for block statements
CallExprData
Data for call/new expressions
CaseClauseData
Data for case/default clauses
CatchClauseData
Data for catch clauses
ClassData
Data for class declarations
CompositeTypeData
Data for union/intersection types
ComputedPropertyData
Data for computed property names
ConditionalExprData
Data for conditional expressions (a ? b : c)
ConditionalTypeData
Data for conditional types
ConstructorData
Data for constructor declarations
DecoratorData
Data for decorator nodes
EnumData
Data for enum declarations
EnumMemberData
Data for enum members
ExportAssignmentData
Data for export assignments
ExportDeclData
Data for export declarations
ExprStatementData
Data for expression statements
ExprWithTypeArgsData
Data for expression with type arguments
ExpressionStatementData
Data for expression statements
ExtendedNodeInfo
Extended node info for nodes that need more than what fits in Node
ForInOfData
Data for for-in/for-of statements
FunctionData
Data for function declarations/expressions/arrows
FunctionTypeData
Data for type nodes (function type, constructor type)
HeritageData
Data for heritage clauses
IdentifierData
Data for identifier nodes (Identifier, PrivateIdentifier)
IfStatementData
Data for if statements
ImportAttributeData
Data for import attribute
ImportAttributesData
Data for import attributes
ImportClauseData
Data for import clauses
ImportDeclData
Data for import declarations
IndexSignatureData
Data for index signatures
IndexedAccessTypeData
Data for indexed access type
InferTypeData
Data for infer type
InterfaceData
Data for interface declarations
JsxAttributeData
Data for JSX attribute
JsxAttributesData
Data for JSX attributes
JsxClosingData
Data for JSX closing elements
JsxElementData
Data for JSX elements
JsxExpressionData
Data for JSX expression
JsxFragmentData
Data for JSX fragments
JsxNamespacedNameData
Data for JSX namespaced name
JsxOpeningData
Data for JSX self-closing/opening elements
JsxSpreadAttributeData
Data for JSX spread attribute
JsxTextData
Data for JSX text
JumpData
Data for break/continue statements
LabeledData
Data for labeled statements
LiteralData
Data for string literals (StringLiteral, template parts)
LiteralExprData
Data for object/array literals
LiteralTypeData
Data for literal types
LoopData
Data for for/while/do loops
MappedTypeData
Data for mapped type
MethodDeclData
Data for method declarations (class methods)
ModuleBlockData
Data for module blocks: { statements }
ModuleData
Data for module/namespace declarations
NamedImportsData
Data for namespace/named imports
NamedTupleMemberData
Data for named tuple member
Node
A thin 16-byte node header for cache-efficient AST storage.
NodeArena
Arena for thin nodes with typed data pools. Provides O(1) allocation and cache-efficient storage.
NodeInfo
Common node information that both arena types can provide. This struct contains the essential fields needed by most consumers.
NodeView
A view into a node that provides convenient access to both the Node header and its type-specific data. This avoids the need to pass the arena around when working with node data.
ParameterData
Data for parameter declarations
ParenthesizedData
Data for parenthesized expressions
PropertyAssignmentData
Data for property assignments
PropertyDeclData
Data for property declarations
QualifiedNameData
Data for qualified names
ReturnData
Data for return/throw statements
ShorthandPropertyData
Data for shorthand property assignments
SignatureData
Data for property/method signatures
SourceFileData
Data for source files
SpecifierData
Data for import/export specifiers
SpreadData
Data for spread assignments
SwitchData
Data for switch statements
TaggedTemplateData
Data for tagged template expressions
TemplateExprData
Data for debugger/empty statements (no data needed, use token)
TemplateLiteralTypeData
Data for template literal types
TemplateSpanData
Data for template spans
TryData
Data for try statements
TupleTypeData
Data for tuple type
TypeAliasData
Data for type alias declarations
TypeAssertionData
Data for as/satisfies/type assertion expressions
TypeLiteralData
Data for type literal
TypeOperatorData
Data for type operator (keyof, unique, readonly)
TypeParameterData
Data for type parameter declarations
TypePredicateData
Data for type predicate
TypeQueryData
Data for type query (typeof)
TypeRefData
Data for type references
UnaryExprData
Data for unary expressions (prefix/postfix)
UnaryExprDataEx
Data for spread/await/yield expressions
VariableData
Data for variable declarations
VariableDeclarationData
Data for variable declarations (individual)
WithData
Data for with statements
WrappedTypeData
Data for optional/rest types

Enums§

NodeCategory
Categories of nodes that share storage pools. Nodes in the same category have similar data layouts.

Traits§

NodeAccess
Trait for unified access to AST nodes across different arena implementations. This allows consumers (binder, checker, emitter) to work with either different arena implementations without code changes.