Skip to content

Commit b097be0

Browse files
committed
perf(@angular/build): process batch locales sequentially in i18n inliner worker
Executing batch locales concurrently via Promise.all within a single worker thread provided no concurrency benefit because inlining operations (MagicString transformations and source map decoding/remapping) are predominantly synchronous and CPU-bound on Node's single-threaded event loop. Holding concurrent MagicString instances, intermediate AST slices, and decoded source map mappings simultaneously inflated peak worker heap and RSS (especially for smaller chunks where up to 8 locales are processed in a single batch). Switching to sequential iteration allows intermediate transformation and mapping structures to be garbage-collected between locales, reducing peak RSS and slightly improving throughput due to reduced GC pressure.
1 parent 73f6bbb commit b097be0

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -276,26 +276,25 @@ export async function inlineFileBatch(
276276
map = rawMap ? (JSON.parse(rawMap) as SourceMapInput) : undefined;
277277
}
278278

279-
const results = await Promise.all(
280-
Array.from(request.locales, async ([locale, translation]) => {
281-
const result = await inlineLocalize(
282-
code,
283-
map,
284-
metadata,
285-
locale,
286-
await loadTranslation(locale, translation),
287-
request.filename,
288-
request.missingTranslation,
289-
);
279+
const results = [];
280+
for (const [locale, translation] of request.locales) {
281+
const result = await inlineLocalize(
282+
code,
283+
map,
284+
metadata,
285+
locale,
286+
await loadTranslation(locale, translation),
287+
request.filename,
288+
request.missingTranslation,
289+
);
290290

291-
return {
292-
locale,
293-
code: result.code,
294-
map: result.map,
295-
messages: result.diagnostics,
296-
};
297-
}),
298-
);
291+
results.push({
292+
locale,
293+
code: result.code,
294+
map: result.map,
295+
messages: result.diagnostics,
296+
});
297+
}
299298

300299
return {
301300
file: request.filename,

0 commit comments

Comments
 (0)