Skip to content

refactor(@angular/build): avoid loading localize tools and babel in i18n inliner worker - #34194

Merged
clydin merged 2 commits into
angular:mainfrom
clydin:perf-i18n-inliner-remove-localize-tools
Sep 29, 2026
Merged

clydin merged 2 commits into
angular:mainfrom
clydin:perf-i18n-inliner-remove-localize-tools

Conversation

@clydin

@clydin clydin commented Sep 28, 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.

Since the inliner only performs string translation replacements using AST locations already discovered via OXC, the full Babel transformation and compiler tooling bundle is unnecessary.

This updates i18n-inliner-worker.ts to directly import low-level runtime functions (ɵtranslate, ɵisMissingTranslationError, ɵmakeTemplateObject) from @angular/localize and manage diagnostics via a direct message array. This completely avoids loading @angular/localize/tools and its heavy transitive dependencies.

…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.

Since the inliner only performs string translation replacements using AST locations
already discovered via OXC, the full Babel transformation and compiler tooling
bundle is unnecessary.

This updates `i18n-inliner-worker.ts` to directly import low-level runtime functions
(`ɵtranslate`, `ɵisMissingTranslationError`, `ɵmakeTemplateObject`) from
`@angular/localize` and manage diagnostics via a direct message array. This completely
avoids loading `@angular/localize/tools` and its heavy transitive dependencies.
@clydin clydin added the target: minor This PR is targeted for the next minor release label Sep 28, 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 remove the dependency on @angular/localize/tools by directly utilizing low-level runtime functions from @angular/localize for message translation. Feedback on the changes suggests improving error handling in the new translateMessage function by verifying that the caught error is an instance of Error before accessing its message property, preventing potential runtime issues.

Comment thread packages/angular/build/src/tools/i18n/i18n-inliner-worker.ts Outdated
@alan-agius4 alan-agius4 added the action: merge The PR is ready for merge by the caretaker label Sep 29, 2026
@clydin
clydin merged commit 4960e70 into angular:main Sep 29, 2026
40 checks passed
@clydin

clydin commented Sep 29, 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-i18n-inliner-remove-localize-tools branch September 29, 2026 13:54
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: 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