Skip to content

Commit 4182b96

Browse files
committed
refactor(@angular/build): precompute expression indexes in i18n inliner 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.
1 parent 0e632f1 commit 4182b96

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

packages/angular/build/src/tools/esbuild/i18n-inliner-worker.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ interface LocalizeCallSite {
321321
end: number;
322322
messageParts: TemplateStringsArray;
323323
expressions: { start: number; end: number }[];
324+
expressionIndexes: number[];
324325
}
325326

326327
/**
@@ -381,12 +382,14 @@ function extractLocalizeMetadata(filename: string, code: string): FileLocalizeMe
381382
start: expr.start,
382383
end: expr.end,
383384
}));
385+
const expressionIndexes = expressions.map((_, index) => index);
384386

385387
callSites.push({
386388
start: node.start,
387389
end: node.end,
388390
messageParts,
389391
expressions,
392+
expressionIndexes,
390393
});
391394
}
392395
}
@@ -448,7 +451,7 @@ async function inlineLocalize(
448451
diagnostics,
449452
translation || {},
450453
callSite.messageParts,
451-
callSite.expressions.map((_, index) => index),
454+
callSite.expressionIndexes,
452455
translation === undefined ? 'ignore' : missingTranslation,
453456
);
454457

0 commit comments

Comments
 (0)