Skip to content

Commit 45a9422

Browse files
clydinalan-agius4
authored andcommittedOct 13, 2022
perf(@angular-devkit/build-angular): use Uint8Arrays for incremental caching with esbuild-based builder
When using the experimental esbuild-based browser application builder in watch mode, the in-memory incremental caching will now use Uint8Arrays where possible to limit the amount of encoding needed when passing data to esbuild. When passing a string to esbuild, it must encode the string prior to sending it. By providing the pre-encoded data from the in-memory cache, this step can be skipped for rebuilds of input files that have not changed. (cherry picked from commit 2adeb6f)
1 parent 9a4e7ff commit 45a9422

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed
 

‎packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ const WINDOWS_SEP_REGEXP = new RegExp(`\\${path.win32.sep}`, 'g');
132132

133133
export class SourceFileCache extends Map<string, ts.SourceFile> {
134134
readonly modifiedFiles = new Set<string>();
135-
readonly babelFileCache = new Map<string, string>();
135+
readonly babelFileCache = new Map<string, Uint8Array>();
136136

137137
invalidate(files: Iterable<string>): void {
138138
this.modifiedFiles.clear();
@@ -247,7 +247,7 @@ export function createCompilerPlugin(
247247

248248
let previousBuilder: ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined;
249249
let previousAngularProgram: NgtscProgram | undefined;
250-
const babelDataCache = new Map<string, string>();
250+
const babelDataCache = new Map<string, Uint8Array>();
251251
const diagnosticCache = new WeakMap<ts.SourceFile, ts.Diagnostic[]>();
252252

253253
build.onStart(async () => {
@@ -466,7 +466,8 @@ export function createCompilerPlugin(
466466
// would need to be added to the key as well.
467467
let contents = babelDataCache.get(data);
468468
if (contents === undefined) {
469-
contents = await transformWithBabel(args.path, data, pluginOptions);
469+
const transformedData = await transformWithBabel(args.path, data, pluginOptions);
470+
contents = Buffer.from(transformedData, 'utf-8');
470471
babelDataCache.set(data, contents);
471472
}
472473

@@ -490,7 +491,8 @@ export function createCompilerPlugin(
490491
let contents = pluginOptions.sourceFileCache?.babelFileCache.get(args.path);
491492
if (contents === undefined) {
492493
const data = await fs.readFile(args.path, 'utf-8');
493-
contents = await transformWithBabel(args.path, data, pluginOptions);
494+
const transformedData = await transformWithBabel(args.path, data, pluginOptions);
495+
contents = Buffer.from(transformedData, 'utf-8');
494496
pluginOptions.sourceFileCache?.babelFileCache.set(args.path, contents);
495497
}
496498

0 commit comments

Comments
 (0)
Please sign in to comment.