From 5efebf87be0955220f07c706cb83efba45532cd0 Mon Sep 17 00:00:00 2001 From: JoostK Date: Fri, 14 Jan 2022 22:44:57 +0100 Subject: [PATCH] perf(compiler-cli): reduce analysis work during incremental rebuilds (#44731) This commit reduces the analysis work that needs to happen during an incremental rebuild by properly recording files for which no traits were found in the set of files that have no traits, such that the same file doesn't have to be reanalyzed during subsequent rebuilds. It also excludes shim files from analysis. PR Close #44731 --- packages/compiler-cli/src/ngtsc/transform/BUILD.bazel | 1 + .../src/ngtsc/transform/src/compilation.ts | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/compiler-cli/src/ngtsc/transform/BUILD.bazel b/packages/compiler-cli/src/ngtsc/transform/BUILD.bazel index 62ace8b72ce..d89d3aa232f 100644 --- a/packages/compiler-cli/src/ngtsc/transform/BUILD.bazel +++ b/packages/compiler-cli/src/ngtsc/transform/BUILD.bazel @@ -17,6 +17,7 @@ ts_library( "//packages/compiler-cli/src/ngtsc/indexer", "//packages/compiler-cli/src/ngtsc/perf", "//packages/compiler-cli/src/ngtsc/reflection", + "//packages/compiler-cli/src/ngtsc/shims", "//packages/compiler-cli/src/ngtsc/translator", "//packages/compiler-cli/src/ngtsc/typecheck/api", "//packages/compiler-cli/src/ngtsc/typecheck/extended/api", diff --git a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts index f2b269f7ba7..6141d3cadb3 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts @@ -15,6 +15,7 @@ import {SemanticDepGraphUpdater, SemanticSymbol} from '../../incremental/semanti import {IndexingContext} from '../../indexer'; import {PerfEvent, PerfRecorder} from '../../perf'; import {ClassDeclaration, DeclarationNode, Decorator, isNamedClassDeclaration, ReflectionHost} from '../../reflection'; +import {isShim} from '../../shims'; import {ProgramTypeCheckAdapter, TypeCheckContext} from '../../typecheck/api'; import {ExtendedTemplateChecker} from '../../typecheck/extended/api'; import {getSourceFile, isExported} from '../../util/src/typescript'; @@ -118,7 +119,7 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { private analyze(sf: ts.SourceFile, preanalyze: true): Promise|undefined; private analyze(sf: ts.SourceFile, preanalyze: boolean): Promise|undefined { // We shouldn't analyze declaration files. - if (sf.isDeclarationFile) { + if (sf.isDeclarationFile || isShim(sf)) { return undefined; } @@ -153,6 +154,13 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { visit(sf); + if (!this.fileToClasses.has(sf)) { + // If no traits were detected in the source file we record the source file itself to not have + // any traits, such that analysis of the source file can be skipped during incremental + // rebuilds. + this.filesWithoutTraits.add(sf); + } + if (preanalyze && promises.length > 0) { return Promise.all(promises).then(() => undefined as void); } else {