Skip to content

perf(@angular/build): use iterative post-order AST traversal for OXC transforms - #33951

Merged
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:perf/oxc-iterative-ast-traversal
Aug 28, 2026
Merged

perf(@angular/build): use iterative post-order AST traversal for OXC transforms#33951
alan-agius4 merged 1 commit into
angular:mainfrom
clydin:perf/oxc-iterative-ast-traversal

Conversation

@clydin

@clydin clydin commented Aug 27, 2026

Copy link
Copy Markdown
Member

Replace the recursive Visitor class from oxc-parser with a specialized iterative post-order AST traversal implementation.

The new traversal implementation eliminates per-file visitor instantiation and internal cache overhead, prunes non-executable TypeScript type subtrees at the root, and uses monomorphic property access for high-frequency AST node types. It also provides stack safety with a single tree-depth array stack and is shared between the OXC transformer and the i18n inliner worker.

@clydin clydin added the target: minor This PR is targeted for the next minor release label Aug 27, 2026
@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Aug 27, 2026
@clydin
clydin marked this pull request as ready for review August 27, 2026 18:59

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a custom, non-recursive post-order AST traversal utility (traversePostOrder) in packages/angular/build/src/tools/oxc/traversal.ts to replace the existing AST visitor and walk utilities in i18n-inliner-worker.ts and oxc-transform.ts. This custom traversal is designed to optimize performance by fast-pathing common AST nodes and pruning non-executable TypeScript type subtrees. The review feedback highlights several critical correctness issues and optimization opportunities in the new traversal logic: (1) pruning all nodes starting with 'TS' incorrectly skips executable TypeScript nodes like enums and namespaces; (2) class and member decorators are currently skipped during traversal; and (3) explicit fast-paths can be added for template literals and tagged template expressions to further improve performance.

Comment thread packages/angular/build/src/tools/oxc/traversal.ts Outdated
Comment thread packages/angular/build/src/tools/oxc/traversal.ts
Comment thread packages/angular/build/src/tools/oxc/traversal.ts
Comment thread packages/angular/build/src/tools/oxc/traversal.ts
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Aug 27, 2026
…transforms

Replace the recursive Visitor class from oxc-parser with a specialized iterative post-order AST traversal implementation.

The new traversal implementation eliminates per-file visitor instantiation and internal cache overhead, prunes non-executable TypeScript type subtrees at the root, and uses monomorphic property access for high-frequency AST node types. It also provides stack safety with a single tree-depth array stack and is shared between the OXC transformer and the i18n inliner worker.
@clydin
clydin force-pushed the perf/oxc-iterative-ast-traversal branch from 4b7e3bb to 46a90e2 Compare August 27, 2026 19:27
@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Aug 28, 2026
@alan-agius4
alan-agius4 merged commit 2b85529 into angular:main Aug 28, 2026
40 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build area: performance Issues related to performance target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants