Skip to content

perf(@angular/build): unify Oxc linking and optimization AST traversal passes - #33880

Merged
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:oxc-unify-linking-optimization-pass
Aug 20, 2026
Merged

perf(@angular/build): unify Oxc linking and optimization AST traversal passes#33880
alan-agius4 merged 2 commits into
angular:mainfrom
alan-agius4:oxc-unify-linking-optimization-pass

Conversation

@alan-agius4

@alan-agius4 alan-agius4 commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Unifies Angular partial declaration linking and production AST optimizations into a single Oxc AST traversal pass.

Previously in transformJavaScriptImpl, when both linking (shouldLink) and production optimizations (advancedOptimizations) were active, Oxc parseSync was invoked twice per file, deserializing ASTs across the Rust/NAPI boundary twice and generating intermediate MagicString sourcemaps that required merging via @ampproject/remapping.

Changes

  1. Unified AST Traversal (oxc-transform.ts):
    • Integrated Angular partial declaration linking into the oxc-transform visitor traversal.
    • When both linking and optimizations are requested, parseSync is invoked only once per file.
    • In CallExpression(node), the visitor checks for partial declarations (such as ɵɵngDeclareComponent) using the new OxcLinker class and links them in-place in the shared MagicString instance while continuing on to elide metadata and annotate top-level pure functions in the same traversal.
  2. Encapsulated Linker (oxc-linker.ts):
    • Refactored oxc-linker.ts to export the OxcLinker class, encapsulating FileLinker, OxcAstHost, and InlineDeclarationScope with a clean linkCallExpression(node) method.
  3. Worker Integration (javascript-transformer-worker.ts):
    • Replaced separate linkWithOxc and transformWithOxc calls with a single unified call to transformWithOxc.

@angular-robot angular-robot Bot added area: performance Issues related to performance area: @angular/build labels Aug 19, 2026
@alan-agius4
alan-agius4 force-pushed the oxc-unify-linking-optimization-pass branch from 1213c1a to 6f022a0 Compare August 19, 2026 12:13
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Aug 19, 2026

@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 refactors the Angular partial declaration linking process by integrating it directly into the unified OXC transformation pass, eliminating the need for a separate AST traversal. A new OxcLinker class is introduced to handle individual CallExpression nodes during the main traversal. Feedback focuses on optimizing this integration: first, by checking if a node is already edited before attempting to link it in oxc-transform.ts to prevent redundant operations and potential magic-string conflicts; second, by passing oxcLink instead of shouldLink to transformWithOxc in javascript-transformer-worker.ts to avoid duplicate linking when the Babel linker has already been executed.

Comment thread packages/angular/build/src/tools/oxc/oxc-transform.ts Outdated
@alan-agius4
alan-agius4 requested review from clydin and dgp1130 and removed request for clydin August 19, 2026 12:14
Program(node) {
adjustTypeScriptEnumsInStatements(node.body);
adjustStaticMembersInStatements(node.body);
'Program:exit'(node) {

@alan-agius4 alan-agius4 Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Changed Program and BlockStatement to 'Program:exit' and 'BlockStatement:exit' so that child AST nodes (like CallExpression) are visited before statement-level IIFE wrapping occurs.

…l passes

Combine partial declaration linking and advanced optimizations into a single AST traversal pass over one Oxc parseSync AST in oxc-transform. This eliminates duplicate AST parses and MagicString sourcemap remapping chains when transforming Angular packages.
@alan-agius4
alan-agius4 force-pushed the oxc-unify-linking-optimization-pass branch from 1c2a4fc to ddc3ecf Compare August 19, 2026 12:42
Comment thread packages/angular/build/src/tools/oxc/oxc-transform_spec.ts
@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 20, 2026
@alan-agius4
alan-agius4 merged commit f4dad31 into angular:main Aug 20, 2026
39 checks passed
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

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

@alan-agius4
alan-agius4 deleted the oxc-unify-linking-optimization-pass branch August 20, 2026 08:28
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