perf(@angular/build): optimize allocations and worker memory lifecycle in i18n inliner - #33964
Open
clydin wants to merge 6 commits into
Open
perf(@angular/build): optimize allocations and worker memory lifecycle in i18n inliner#33964clydin wants to merge 6 commits into
clydin wants to merge 6 commits into
Conversation
…er worker Previously, callSite.expressions.map((_, index) => index) was evaluated on every $localize call site for every locale inside inlineLocalize. In bundles with hundreds of call sites processed across multiple locales in a batch, this resulted in thousands of redundant small array allocations. expressionIndexes is now precomputed once during AST extraction in extractLocalizeMetadata and stored on LocalizeCallSite, eliminating per-locale index array allocations in the worker transformation loop.
…tch loop Instantiate codeBlob and mapBlob once per file outside the batch loop instead of re-creating new Blob instances on each batch slice. Blobs are immutable, read-only binary handles and can be safely shared across multiple worker batch tasks concurrently.
…nliner Streamline the asynchronous cache resolution in inlineAll by removing the intermediate CacheCheckItem interface and array mapping allocations. Results are now assigned directly to fileResultsByLocale on hit or pushed to uncachedByFile on miss. When no persistent cache is configured, a fast path directly queues uncached files without promise or hash overhead.
…ing in i18n inliner Introduce generation tracking in I18nInliner and worker batch tasks to guarantee long-term worker caches (fileDataCache and deserializedTranslations) are wiped whenever a new inlining pass or rebuild begins (e.g. watch mode or shared worker pools).
…n i18n inliner worker
Consolidate the 3 chained string replacement passes (unescaping double quotes,
escaping backticks, and escaping ${ delimiters) into a single regex pass in
escapeTemplatePart. This eliminates 3 intermediate string allocations and
reduces 3 regex scans to 1 on every translated template literal part.
There was a problem hiding this comment.
Code Review
This pull request introduces a generation counter to clear long-term worker caches across multiple runs of the i18n inliner, ensuring correctness in watch mode. It also refactors template literal escaping into a single-pass helper function and optimizes cache-checking logic. Feedback on the changes highlights that the new asynchronous cache-checking logic introduces non-determinism in the order of uncached file entries due to varying cache lookup resolution times. A deterministic approach using per-file Promise.all is suggested to ensure build reproducibility and ease debugging.
…he checks Resolve asynchronous cache checks on a per-file basis using Promise.all to ensure windowLocales ordering is preserved within uncachedByFile regardless of disk I/O resolution timing. Also avoids pre-populating and deleting empty arrays in uncachedByFile.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
注册 for free
to join this conversation on GitHub.
Already have an account?
登录 to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces a series of focused optimizations to reduce heap allocations, streamline cache pipeline resolution, and ensure clean worker memory lifecycle in the
I18nInliner.