Skip to content

Commit ab2ed18

Browse files
mattlewis92alan-agius4
authored andcommitted
perf(@angular/build): hash the i18n inline cache key options once per locale
Each file's persistent cache key is built from `file.hash`, the filename, and the inline options. The options include the locale's translations, so the multi-megabyte set of messages was fed into a fresh SHA-256 for every localized file: for an application with a few thousand localized chunks that is tens of gigabytes of hash input per build, all of it recomputing the same value. The options are digested once per locale instead, so each file's key is derived from a fixed 32 bytes. This changes the keys, so the first build after this change repopulates the i18n cache. (cherry picked from commit 33b3054)
1 parent 712971c commit ab2ed18

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ export class I18nInliner {
157157

158158
let cacheResultPromise = Promise.resolve(null);
159159
if (this.#cache) {
160-
fileCacheKeyBase ??= Buffer.from(
161-
JSON.stringify({ locale, translation, missingTranslation, shouldOptimize }),
162-
'utf-8',
163-
);
160+
// The options are digested here so that each file's key is derived from a fixed number
161+
// of bytes. Hashing the options directly would re-hash the full set of messages, which
162+
// can be several megabytes, once for every file.
163+
fileCacheKeyBase ??= createHash('sha256')
164+
.update(JSON.stringify({ locale, translation, missingTranslation, shouldOptimize }))
165+
.digest();
164166

165167
// NOTE: If additional options are added, this may need to be updated.
166168
// TODO: Consider xxhash or similar instead of SHA256

0 commit comments

Comments
 (0)