Skip to content

[22.2.x]refactor(@angular/build): avoid loading localize tools and babel in i18n inliner worker - #34213

Merged
clydin merged 2 commits into
angular:22.2.xfrom
clydin:perf-inliner-worker-startup-22.2.x
Sep 30, 2026
Merged

clydin merged 2 commits into
angular:22.2.xfrom
clydin:perf-inliner-worker-startup-22.2.x

Conversation

@clydin

@clydin clydin commented Sep 30, 2026

Copy link
Copy Markdown
Member

Previously, i18n-inliner-worker.ts dynamically loaded @angular/localize/tools
to invoke its translate() function and Diagnostics class. Importing
@angular/localize/tools eagerly pulls in @babel/core, @angular/compiler-cli,
and @angular/compiler, consuming ~180 ms of CPU latency and ~32 MB of heap per
worker thread upon first translation.

…18n inliner worker

Previously, `i18n-inliner-worker.ts` dynamically loaded `@angular/localize/tools`
to invoke its `translate()` function and `Diagnostics` class. Importing
`@angular/localize/tools` eagerly pulls in `@babel/core`, `@angular/compiler-cli`,
and `@angular/compiler`, consuming ~180 ms of CPU latency and ~32 MB of heap per
worker thread upon first translation.
…er worker

Previously, `@ampproject/remapping` was statically imported at the top level
of `i18n-inliner-worker.ts`, eagerly pulling in 5 packages
(`@ampproject/remapping` and 4 sub-dependencies) upon worker initialization.

In typical workflows or when sourcemaps are not requested for inlining,
remapping is never executed.

This changes the import of `@ampproject/remapping` to be dynamic so that
it is only loaded when a file actually requires sourcemap remapping.
@clydin clydin added the target: patch This PR is targeted for the next patch release label Sep 30, 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 i18n inliner worker to use low-level runtime functions from @angular/localize directly, eliminating the need to dynamically load @angular/localize/tools. It also optimizes startup by lazy-loading @ampproject/remapping. Feedback highlights a potential performance regression when translations is undefined; passing an empty object to ɵtranslate throws expensive exceptions for every message. A fast-path implementation is suggested to bypass translation lookup and avoid this overhead.

Comment thread packages/angular/build/src/tools/i18n/i18n-inliner-worker.ts
@clydin clydin added the action: review The PR is still awaiting reviews from at least one requested reviewer label Sep 30, 2026
@clydin
clydin requested a review from alan-agius4 September 30, 2026 16:35
@clydin clydin 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 Sep 30, 2026
@clydin
clydin merged commit 19455d8 into angular:22.2.x Sep 30, 2026
38 checks passed
@clydin

clydin commented Sep 30, 2026

Copy link
Copy Markdown
Member Author

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

@clydin
clydin deleted the perf-inliner-worker-startup-22.2.x branch September 30, 2026 17:03
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 target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants