Skip to content

Commit 1831d2f

Browse files
committed
Instead of iterating over resolutions to invalidate per global cache pass, invalidate them at usage site
1 parent f9123f9 commit 1831d2f

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
@@ -757,6 +757,9 @@ export function createResolutionCache(
757757
hasInvalidatedResolutions: path =>
758758
customHasInvalidatedResolutions(path) ||
759759
allModuleAndTypeResolutionsAreInvalidated ||
760+
resolutionsWithGlobalCachePassAreInvalidated ||
761+
resolutionsWithoutGlobalCachePassAreInvalidated ||
762+
unresolvedResolutionsWithGlobalCachePassAreInvalidated ||
760763
!!collected?.has(path),
761764
hasInvalidatedLibResolutions: libFileName =>
762765
customHasInvalidatedLibResolutions(libFileName) ||
@@ -794,6 +797,9 @@ export function createResolutionCache(
794797

795798
function finishCachingPerDirectoryResolution(newProgram: Program | undefined, oldProgram: Program | undefined) {
796799
allModuleAndTypeResolutionsAreInvalidated = false;
800+
resolutionsWithGlobalCachePassAreInvalidated = false;
801+
resolutionsWithoutGlobalCachePassAreInvalidated = false;
802+
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
797803
nonRelativeExternalModuleResolutions.forEach(watchFailedLookupLocationOfNonRelativeModuleResolutions);
798804
nonRelativeExternalModuleResolutions.clear();
799805
// Update file watches
@@ -852,6 +858,13 @@ export function createResolutionCache(
852858
}
853859
}
854860

861+
function isResolutionInvalidatedPerGlobalCacheOptions(resolution: ResolutionWithFailedLookupLocations) {
862+
if (resolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution) return true;
863+
if (resolutionsWithoutGlobalCachePassAreInvalidated && resolution.globalCacheResolution === false) return true;
864+
if (unresolvedResolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution && isUnresolvedOrResolvedToJs(resolution as ResolvedModuleWithFailedLookupLocations)) return true;
865+
return false;
866+
}
867+
855868
interface ResolveNamesWithLocalCacheInput<Entry, SourceFile, T extends ResolutionWithFailedLookupLocations, R extends ResolutionWithResolvedFileName> {
856869
entries: readonly Entry[];
857870
containingFile: string;
@@ -897,7 +910,13 @@ export function createResolutionCache(
897910
// Resolution is valid if it is present and not invalidated
898911
if (
899912
!seenNamesInFile.has(name, mode) &&
900-
(allModuleAndTypeResolutionsAreInvalidated || unmatchedRedirects || !resolution || resolution.isInvalidated)
913+
(
914+
allModuleAndTypeResolutionsAreInvalidated ||
915+
unmatchedRedirects ||
916+
!resolution ||
917+
resolution.isInvalidated ||
918+
isResolutionInvalidatedPerGlobalCacheOptions(resolution)
919+
)
901920
) {
902921
const existingResolution = resolution;
903922
resolution = loader.resolve(name, mode);
@@ -1589,9 +1608,6 @@ export function createResolutionCache(
15891608
startsWithPathChecks = undefined;
15901609
isInDirectoryChecks = undefined;
15911610
affectingPathChecks = undefined;
1592-
resolutionsWithGlobalCachePassAreInvalidated = false;
1593-
resolutionsWithoutGlobalCachePassAreInvalidated = false;
1594-
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
15951611
return true;
15961612
}
15971613
let invalidated = false;
@@ -1605,11 +1621,7 @@ export function createResolutionCache(
16051621
affectingPathChecksForFile = undefined;
16061622
}
16071623

1608-
if (
1609-
!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks &&
1610-
!resolutionsWithGlobalCachePassAreInvalidated && !resolutionsWithoutGlobalCachePassAreInvalidated &&
1611-
!unresolvedResolutionsWithGlobalCachePassAreInvalidated
1612-
) {
1624+
if (!failedLookupChecks && !startsWithPathChecks && !isInDirectoryChecks && !affectingPathChecks) {
16131625
return invalidated;
16141626
}
16151627

@@ -1620,9 +1632,6 @@ export function createResolutionCache(
16201632
isInDirectoryChecks = undefined;
16211633
invalidated = invalidateResolutions(resolutionsWithOnlyAffectingLocations, canInvalidatedFailedLookupResolutionWithAffectingLocation) || invalidated;
16221634
affectingPathChecks = undefined;
1623-
resolutionsWithGlobalCachePassAreInvalidated = false;
1624-
resolutionsWithoutGlobalCachePassAreInvalidated = false;
1625-
unresolvedResolutionsWithGlobalCachePassAreInvalidated = false;
16261635
return invalidated;
16271636
}
16281637

@@ -1642,9 +1651,6 @@ export function createResolutionCache(
16421651
}
16431652

16441653
function canInvalidatedFailedLookupResolutionWithAffectingLocation(resolution: ResolutionWithFailedLookupLocations) {
1645-
if (resolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution) return true;
1646-
if (resolutionsWithoutGlobalCachePassAreInvalidated && resolution.globalCacheResolution === false) return true;
1647-
if (unresolvedResolutionsWithGlobalCachePassAreInvalidated && resolution.globalCacheResolution && isUnresolvedOrResolvedToJs(resolution as ResolvedModuleWithFailedLookupLocations)) return true;
16481654
return !!affectingPathChecks && resolution.affectingLocations?.some(location => affectingPathChecks!.has(location));
16491655
}
16501656

0 commit comments

Comments
 (0)