Skip to content

refactor(@angular/build): lazily evaluate sideEffects in javascript transformer - #34059

Open
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/lazy-side-effects
Open

refactor(@angular/build): lazily evaluate sideEffects in javascript transformer#34059
clydin wants to merge 1 commit into
angular:mainfrom
clydin:perf/lazy-side-effects

Conversation

@clydin

@clydin clydin commented Sep 9, 2026

Copy link
Copy Markdown
Member

Previously, compiler-plugin.ts eagerly resolved sideEffects for every JavaScript file loaded during bundling by calling await hasSideEffects(request), which executes esbuild's asynchronous build.resolve to inspect package.json.

Within the JavaScript transformer, sideEffects is only needed in two specific locations: when checking if a file belongs to node_modules/@angular/ to apply top-level pure function annotations, and when determining whether to wrap decorators in side-effect-free files that lack primary candidate tokens.

The sideEffects check is now evaluated lazily. Method signatures on transformData and transformFile have been simplified to accept a TransformOptions interface with an optional async sideEffects resolver callback. Inside hasAdvancedOptimizationCandidates, the resolver is only evaluated if the file matches the node_modules/@angular/ path pattern or contains decorator tokens without primary optimization tokens. If the candidate check does not query sideEffects, the resolver is never invoked, eliminating unnecessary build.resolve calls for bypassed files, linker-only modules, and files matching primary optimization tokens.

…ransformer

Previously, compiler-plugin.ts eagerly resolved sideEffects for every JavaScript file loaded during bundling by calling await hasSideEffects(request), which executes esbuild's asynchronous build.resolve to inspect package.json.

Within the JavaScript transformer, sideEffects is only needed in two specific locations: when checking if a file belongs to node_modules/@angular/ to apply top-level pure function annotations, and when determining whether to wrap decorators in side-effect-free files that lack primary candidate tokens.

The sideEffects check is now evaluated lazily. Method signatures on transformData and transformFile have been simplified to accept a TransformOptions interface with an optional async sideEffects resolver callback. Inside hasAdvancedOptimizationCandidates, the resolver is only evaluated if the file matches the node_modules/@angular/ path pattern or contains decorator tokens without primary optimization tokens. If the candidate check does not query sideEffects, the resolver is never invoked, eliminating unnecessary build.resolve calls for bypassed files, linker-only modules, and files matching primary optimization tokens.
@clydin
clydin force-pushed the perf/lazy-side-effects branch from 5598ecb to 0c7035a Compare September 9, 2026 18:46
@clydin
clydin marked this pull request as ready for review September 9, 2026 18:52

@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 JavaScriptTransformer to accept a lazy sideEffects resolver callback instead of a pre-evaluated boolean. It introduces a new TransformOptions interface to group transformation parameters, moves caching logic from transformFile to transformData to ensure both paths benefit from caching, and updates the compiler plugin and tests accordingly. There are no review comments, so no feedback is provided.

@clydin clydin added target: minor This PR is targeted for the next minor release action: review The PR is still awaiting reviews from at least one requested reviewer labels Sep 9, 2026
@clydin
clydin requested a review from alan-agius4 September 9, 2026 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

action: review The PR is still awaiting reviews from at least one requested reviewer area: @angular/build target: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant