From 768216f477ab6fe0998588e672336e13c9a51d4c Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Fri, 23 Aug 2019 17:11:40 -0400 Subject: [PATCH] Prevent excessive compilation of files within a cycle Cycles within a project previously would emit (to both memory and then later to disk) multiple times per file. This would not have been possible without the large amount of time that @bjlaub put into debugging. --- src/compiler/builder.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/compiler/builder.ts b/src/compiler/builder.ts index 7af7be17f5534..87f463f421cee 100644 --- a/src/compiler/builder.ts +++ b/src/compiler/builder.ts @@ -997,7 +997,21 @@ namespace ts { } function addToAffectedFilesPendingEmit(state: BuilderProgramState, affectedFilesPendingEmit: readonly Path[]) { - state.affectedFilesPendingEmit = concatenate(state.affectedFilesPendingEmit, affectedFilesPendingEmit); + const actualAffectedFilesPendingEmit = affectedFilesPendingEmit.filter((f) => { + // No point in concatenating if its already in there + if (state.affectedFilesPendingEmit && state.affectedFilesPendingEmit.some((v) => v === f)) { + return false; + } + + return true; + }); + + if (actualAffectedFilesPendingEmit.length === 0) { + // We filtered everything out, abort. + return; + } + + state.affectedFilesPendingEmit = concatenate(state.affectedFilesPendingEmit, actualAffectedFilesPendingEmit); // affectedFilesPendingEmitIndex === undefined // - means the emit state.affectedFilesPendingEmit was undefined before adding current affected files // so start from 0 as array would be affectedFilesPendingEmit