Skip to content

Commit 87644ae

Browse files
committed
Instead of iterating over resolutions to invalidate per global cache pass, invalidate them at usage site
1 parent 85cc158 commit 87644ae

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

src/compiler/resolutionCache.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,9 @@ export function createResolutionCache(
716716
hasInvalidatedResolutions: path =>
717717
customHasInvalidatedResolutions(path) ||
718718
allModuleAndTypeResolutionsAreInvalidated ||
719+
resolutionsWithGlobalCachePassAreInvalidated ||
720+
resolutionsWithoutGlobalCachePassAreInvalidated ||
721+
unresolvedResolutionsWithGlobalCachePassAreInvalidated ||
719722
!!collected?.has(path),
720723
hasInvalidatedLibResolutions: libFileName =>
721724
customHasInvalidatedLibResolutions(libFileName) ||
@@ -752,6 +755,9 @@ export function createResolutionCache(
752755

753756
function finishCachingPerDirectoryResolution(newProgram: Program | undefined, oldProgram: Program | undefined) {
754757
allModuleAndTypeResolutionsAreInvalidated = false;
758+
resolutionsWithGlobalCachePassAreInvalidated = false;
759+
resolutionsWithoutGlobalCachePassAreInvalidated = false;
760+
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
755761
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
756762
nonRelativeExternalModuleResolutions.clear();
757763
// Update file watches
@@ -801,6 +807,13 @@ export function createResolutionCache(
801807
}
802808
}
803809

810+
function isResolutionInvalidatedPerGlobalCacheOptions(resolution: ResolutionWithFailedLookupLocations) {
811+
if (resolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution) return true;
812+
if (resolutionsWithoutGlobalCachePassAreInvalidated && resolution.globalCacheResolution === false) return true;
813+
if (unresolvedResolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution && isUnresolvedOrResolvedToJs(resolution as ResolvedModuleWithFailedLookupLocations)) return true;
814+
return false;
815+
}
816+
804817
interface ResolveNamesWithLocalCacheInput<Entry, SourceFile, T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName> {
805818
entries: readonly Entry[];
806819
containingFile: string;
@@ -846,7 +859,13 @@ export function createResolutionCache(
846859
// Resolution is valid if it is present and not invalidated
847860
if (
848861
!seenNamesInFile.has(name, mode) &&
849-
(allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated)
862+
(
863+
allModuleAndTypeResolutionsAreInvalidated ||
864+
unmatchedRedirects ||
865+
!resolution ||
866+
resolution.isInvalidated ||
867+
isResolutionInvalidatedPerGlobalCacheOptions(resolution)
868+
)
850869
) {
851870
const existingResolution = resolution;
852871
resolution = loader.resolve(name, mode);
@@ -1455,9 +1474,6 @@ export function createResolutionCache(
14551474
startsWithPathChecks = undefined;
14561475
isInDirectoryChecks = undefined;
14571476
affectingPathChecks = undefined;
1458-
resolutionsWithGlobalCachePassAreInvalidated = false;
1459-
resolutionsWithoutGlobalCachePassAreInvalidated = false;
1460-
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
14611477
return true;
14621478
}
14631479
let invalidated = false;
@@ -1471,11 +1487,7 @@ export function createResolutionCache(
14711487
affectingPathChecksForFile = undefined;
14721488
}
14731489

1474-
if (
1475-
!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks &&
1476-
!resolutionsWithGlobalCachePassAreInvalidated && !resolutionsWithoutGlobalCachePassAreInvalidated &&
1477-
!unresolvedResolutionsWithGlobalCachePassAreInvalidated
1478-
) {
1490+
if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
14791491
return invalidated;
14801492
}
14811493

@@ -1486,9 +1498,6 @@ export function createResolutionCache(
14861498
isInDirectoryChecks = undefined;
14871499
invalidated = invalidateResolutions(resolutionsWithOnlyAffectingLocations, canInvalidatedFailedLookupResolutionWithAffectingLocation) || invalidated;
14881500
affectingPathChecks = undefined;
1489-
resolutionsWithGlobalCachePassAreInvalidated = false;
1490-
resolutionsWithoutGlobalCachePassAreInvalidated = false;
1491-
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
14921501
return invalidated;
14931502
}
14941503

@@ -1508,9 +1517,6 @@ export function createResolutionCache(
15081517
}
15091518

15101519
function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution: ResolutionWithFailedLookupLocations) {
1511-
if (resolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution) return true;
1512-
if (resolutionsWithoutGlobalCachePassAreInvalidated && resolution.globalCacheResolution === false) return true;
1513-
if (unresolvedResolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution && isUnresolvedOrResolvedToJs(resolution as ResolvedModuleWithFailedLookupLocations)) return true;
15141520
return !!affectingPathChecks && resolution.affectingLocations?.some(location => affectingPathChecks!.has(location));
15151521
}
15161522

0 commit comments

Comments
 (0)