Skip to content

Commit 5029a61

Browse files
committed
Cache global dependency graph and invalidate it only if doing full reload of the project or resetting builder context
1 parent ec6c9ea commit 5029a61

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

src/compiler/tsbuild.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ namespace ts {
404404
/** Map from config file name to up-to-date status */
405405
const projectStatus = createFileMap<UpToDateStatus>(toPath);
406406
const missingRoots = createMap<true>();
407+
let globalDependencyGraph: DependencyGraph | false | undefined;
407408

408409
// Watch state
409410
// TODO(shkamat): this should be really be diagnostics but thats for later time
@@ -446,6 +447,7 @@ namespace ts {
446447
unchangedOutputs.clear();
447448
projectStatus.clear();
448449
missingRoots.clear();
450+
globalDependencyGraph = undefined;
449451

450452
diagnostics.clear();
451453
projectPendingBuild.clear();
@@ -527,7 +529,6 @@ namespace ts {
527529
function watchConfigFile(resolved: ResolvedConfigFileName) {
528530
if (!allWatchedConfigFiles.hasKey(resolved)) {
529531
allWatchedConfigFiles.setValue(resolved, hostWithWatch.watchFile(resolved, () => {
530-
configFileCache.removeKey(resolved);
531532
invalidateProjectAndScheduleBuilds(resolved, ConfigFileProgramReloadLevel.Full);
532533
}));
533534
}
@@ -626,7 +627,10 @@ namespace ts {
626627
}
627628

628629
function getGlobalDependencyGraph() {
629-
return getBuildGraph(rootNames);
630+
if (globalDependencyGraph === undefined) {
631+
globalDependencyGraph = getBuildGraph(rootNames) || false;
632+
}
633+
return globalDependencyGraph || undefined;
630634
}
631635

632636
function getUpToDateStatus(project: ParsedCommandLine | undefined): UpToDateStatus {
@@ -811,12 +815,17 @@ namespace ts {
811815
}
812816

813817
function invalidateResolvedProject(resolved: ResolvedConfigFileName, reloadLevel?: ConfigFileProgramReloadLevel) {
818+
if (reloadLevel === ConfigFileProgramReloadLevel.Full) {
819+
configFileCache.removeKey(resolved);
820+
globalDependencyGraph = undefined;
821+
}
814822
projectStatus.removeKey(resolved);
815823
if (options.watch) {
816824
diagnostics.removeKey(resolved);
817825
}
818826

819827
if (addProjToQueue(resolved, reloadLevel)) {
828+
// TODO: instead of adding the dependent project to queue right away postpone this
820829
const dependencyGraph = getGlobalDependencyGraph();
821830
if (dependencyGraph) {
822831
queueBuildForDownstreamReferences(resolved, dependencyGraph);
@@ -1126,9 +1135,9 @@ namespace ts {
11261135
projectStatus.setValue(proj.options.configFilePath as ResolvedConfigFilePath, { type: UpToDateStatusType.UpToDate, newestDeclarationFileContentChangedTime: priorNewestUpdateTime } as UpToDateStatus);
11271136
}
11281137

1129-
function getFilesToClean(configFileNames: ReadonlyArray<string>): string[] | undefined {
1138+
function getFilesToClean(): string[] | undefined {
11301139
// Get the same graph for cleaning we'd use for building
1131-
const graph = getBuildGraph(configFileNames);
1140+
const graph = getGlobalDependencyGraph();
11321141
if (graph === undefined) return undefined;
11331142

11341143
const filesToDelete: string[] = [];
@@ -1149,7 +1158,7 @@ namespace ts {
11491158
}
11501159

11511160
function cleanAllProjects() {
1152-
const filesToDelete = getFilesToClean(rootNames);
1161+
const filesToDelete = getFilesToClean();
11531162
if (filesToDelete === undefined) {
11541163
reportStatus(Diagnostics.Skipping_clean_because_not_all_projects_could_be_located);
11551164
return ExitStatus.DiagnosticsPresent_OutputsSkipped;

0 commit comments

Comments
 (0)