perf(ivy): switch ngtsc to use single-file emit (#29147)
In the TypeScript compiler API, emit() can be performed either on a single ts.SourceFile or on the entire ts.Program simultaneously. ngtsc previously used whole-program emit, which was convenient to use while spinning up the project but has a significant drawback: it causes a type checking operation to occur for the whole program, including .d.ts files. In large Bazel environments (such as Google's codebase), an ngtsc invocation can have a few .ts files and thousands of .d.ts inputs. This unwanted type checking is therefore a significant drain on performance. This commit switches ngtsc to emit each .ts file individually, avoiding the unwanted type checking. PR Close #29147
This commit is contained in:
parent
142ac41cac
commit
37c5a26421
@ -293,8 +293,14 @@ export class NgtscProgram implements api.Program {
|
|||||||
beforeTransforms.push(...customTransforms.beforeTs);
|
beforeTransforms.push(...customTransforms.beforeTs);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the emit, including a custom transformer that will downlevel the Ivy decorators in code.
|
const emitResults: ts.EmitResult[] = [];
|
||||||
const emitResult = emitCallback({
|
for (const targetSourceFile of this.tsProgram.getSourceFiles()) {
|
||||||
|
if (targetSourceFile.isDeclarationFile) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
emitResults.push(emitCallback({
|
||||||
|
targetSourceFile,
|
||||||
program: this.tsProgram,
|
program: this.tsProgram,
|
||||||
host: this.host,
|
host: this.host,
|
||||||
options: this.options,
|
options: this.options,
|
||||||
@ -304,8 +310,11 @@ export class NgtscProgram implements api.Program {
|
|||||||
after: customTransforms && customTransforms.afterTs,
|
after: customTransforms && customTransforms.afterTs,
|
||||||
afterDeclarations: afterDeclarationsTransforms,
|
afterDeclarations: afterDeclarationsTransforms,
|
||||||
},
|
},
|
||||||
});
|
}));
|
||||||
return emitResult;
|
}
|
||||||
|
|
||||||
|
// Run the emit, including a custom transformer that will downlevel the Ivy decorators in code.
|
||||||
|
return ((opts && opts.mergeEmitResultsCallback) || mergeEmitResults)(emitResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
private compileTypeCheckProgram(ctx: TypeCheckContext): ReadonlyArray<ts.Diagnostic> {
|
private compileTypeCheckProgram(ctx: TypeCheckContext): ReadonlyArray<ts.Diagnostic> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user