Repository navigation
[22.2.x]refactor(@angular/build): avoid loading localize tools and babel in i18n inliner worker - #34213
Conversation
…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.
There was a problem hiding this comment.
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.
|
This PR was merged into the repository. The changes were merged into the following branches:
|
|
This pull request has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Previously,
i18n-inliner-worker.tsdynamically loaded@angular/localize/toolsto invoke its
translate()function andDiagnosticsclass. Importing@angular/localize/toolseagerly pulls in@babel/core,@angular/compiler-cli,and
@angular/compiler, consuming ~180 ms of CPU latency and ~32 MB of heap perworker thread upon first translation.