From 5fb23ecceaccf0629308dd50210b65f67d51f024 Mon Sep 17 00:00:00 2001 From: JoostK Date: Sat, 12 Jun 2021 16:46:24 +0200 Subject: [PATCH] perf(compiler-cli): skip analysis in incremental builds for files without Angular behavior (#42562) In an incremental rebuild, the compiler attempts to reuse as much analysis data from a prior compilation as possible to avoid doing the analysis work again. For source files without Angular behavior however, no analysis data would be recorded such that the source file had to be reanalyzed each rebuild, even if it has not changed. This commit avoids the analysis of such source files by registering these files as not containing any Angular behavior; allowing subsequent rebuilds to avoid the analysis work. PR Close #42562 --- .../src/ngtsc/transform/src/compilation.ts | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts index a5bf2798ae..87186fbb2b 100644 --- a/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts +++ b/packages/compiler-cli/src/ngtsc/transform/src/compilation.ts @@ -82,6 +82,12 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { */ protected fileToClasses = new Map>(); + /** + * Tracks which source files have been analyzed but did not contain any traits. This set allows + * the compiler to skip analyzing these files in an incremental rebuild. + */ + protected filesWithoutTraits = new Set(); + private reexportMap = new Map>(); private handlersByName = @@ -121,12 +127,17 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { const priorWork = this.incrementalBuild.priorAnalysisFor(sf); if (priorWork !== null) { - for (const priorRecord of priorWork) { - this.adopt(priorRecord); - } - this.perf.eventCount(PerfEvent.SourceFileReuseAnalysis); - this.perf.eventCount(PerfEvent.TraitReuseAnalysis, priorWork.length); + + if (priorWork.length > 0) { + for (const priorRecord of priorWork) { + this.adopt(priorRecord); + } + + this.perf.eventCount(PerfEvent.TraitReuseAnalysis, priorWork.length); + } else { + this.filesWithoutTraits.add(sf); + } // Skip the rest of analysis, as this file's prior traits are being reused. return; @@ -176,6 +187,9 @@ export class TraitCompiler implements ProgramTypeCheckAdapter { } result.set(sf, records); } + for (const sf of this.filesWithoutTraits) { + result.set(sf, []); + } return result; }