Skip to content

Commit 03bfca3

Browse files
committed
Track cache version on BuilderState
In practice, `updateExportedFilesMapFromCache` is called repeatedly without the cache changing in between. When this occurs, there's no need to update the `BuilderState` (this was already the net effect, but it took a long time to determine that no work was required).
1 parent a1d0d26 commit 03bfca3

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/compiler/builderState.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ namespace ts {
4848
*/
4949
readonly exportedModulesMap: BuilderState.ManyToManyPathMap | undefined;
5050

51+
previousCache?: {
52+
id: number,
53+
version: number,
54+
};
55+
5156
/**
5257
* true if file version is used as signature
5358
* This helps in delaying the calculation of the d.ts hash as version for the file till reasonable time
@@ -488,6 +493,22 @@ namespace ts {
488493
export function updateExportedFilesMapFromCache(state: BuilderState, exportedModulesMapCache: ManyToManyPathMap | undefined) {
489494
if (exportedModulesMapCache) {
490495
Debug.assert(!!state.exportedModulesMap);
496+
497+
const cacheId = exportedModulesMapCache.id;
498+
const cacheVersion = exportedModulesMapCache.version();
499+
if (state.previousCache) {
500+
if (state.previousCache.id === cacheId && state.previousCache.version === cacheVersion) {
501+
// If this is the same cache at the same version as last time this BuilderState
502+
// was updated, there's not need to update again
503+
return;
504+
}
505+
state.previousCache.id = cacheId;
506+
state.previousCache.version = cacheVersion;
507+
}
508+
else {
509+
state.previousCache = { id: cacheId, version: cacheVersion };
510+
}
511+
491512
exportedModulesMapCache.deletedKeys()?.forEach(path => state.exportedModulesMap!.deleteKey(path));
492513
exportedModulesMapCache.forEach((exportedModules, path) => state.exportedModulesMap!.set(path, exportedModules));
493514
}

0 commit comments

Comments
 (0)