Skip to content

Commit 627fbcb

Browse files
authored
Add fast path exits if we are retaining all configured projects (#59689)
1 parent 2192336 commit 627fbcb

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/server/editorServices.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4456,7 +4456,7 @@ export class ProjectService {
44564456
toRetainConfiguredProjects: Set<ConfiguredProject> | undefined,
44574457
openFilesWithRetainedConfiguredProject: Set<Path> | undefined,
44584458
externalProjectsRetainingConfiguredProjects: Set<string> | undefined,
4459-
) {
4459+
): Set<ConfiguredProject> {
44604460
const toRemoveConfiguredProjects = new Set(this.configuredProjects.values());
44614461
const markOriginalProjectsAsUsed = (project: Project) => {
44624462
if (project.originalConfiguredProjects && (isConfiguredProject(project) || !project.isOrphan())) {
@@ -4469,6 +4469,8 @@ export class ProjectService {
44694469
}
44704470
};
44714471
toRetainConfiguredProjects?.forEach(retainConfiguredProject);
4472+
// Everything needs to be retained, fast path to skip all the work
4473+
if (!toRemoveConfiguredProjects.size) return toRemoveConfiguredProjects;
44724474

44734475
// Do not remove configured projects that are used as original projects of other
44744476
this.inferredProjects.forEach(markOriginalProjectsAsUsed);
@@ -4479,7 +4481,10 @@ export class ProjectService {
44794481
projects.forEach(retainConfiguredProject);
44804482
}
44814483
});
4482-
this.openFiles.forEach((_projectRootPath, path) => {
4484+
// Everything needs to be retained, fast path to skip all the work
4485+
if (!toRemoveConfiguredProjects.size) return toRemoveConfiguredProjects;
4486+
4487+
forEachEntry(this.openFiles, (_projectRootPath, path) => {
44834488
if (openFilesWithRetainedConfiguredProject?.has(path)) return;
44844489
const info = this.getScriptInfoForPath(path)!;
44854490
// Part of external project
@@ -4491,15 +4496,21 @@ export class ProjectService {
44914496
);
44924497
if (result?.defaultProject) {
44934498
result?.seenProjects.forEach(retainConfiguredProject);
4499+
// Everything needs to be retained, fast path to skip all the work
4500+
if (!toRemoveConfiguredProjects.size) return toRemoveConfiguredProjects;
44944501
}
44954502
});
44964503

4504+
// Everything needs to be retained, fast path to skip all the work
4505+
if (!toRemoveConfiguredProjects.size) return toRemoveConfiguredProjects;
4506+
44974507
// Retain all the configured projects that have pending updates
44984508
// or the ones that is referencing retained project (or to be retained)
4499-
this.configuredProjects.forEach(project => {
4509+
forEachEntry(this.configuredProjects, project => {
45004510
if (toRemoveConfiguredProjects.has(project)) {
45014511
if (isPendingUpdate(project) || forEachReferencedProject(project, isRetained)) {
45024512
retainConfiguredProject(project);
4513+
if (!toRemoveConfiguredProjects.size) return toRemoveConfiguredProjects;
45034514
}
45044515
}
45054516
});

0 commit comments

Comments
 (0)