From 87a6e2c5d73a43610bf21abde710a6c9ae973756 Mon Sep 17 00:00:00 2001 From: Blake Embrey Date: Sun, 15 Sep 2019 17:24:15 -0700 Subject: [PATCH] Revert "List all files in memory cache improves perf 1.4x" This reverts commit 6dad5ad34d0cea80ff9be75d9a77e07f19d9175a. --- src/index.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 48d2c72ee..f9500ce5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,7 +81,7 @@ class MemoryCache { fileContents = new Map() fileVersions = new Map() - constructor (rootFileNames: string[] = []) { + constructor (public rootFileNames: string[] = []) { for (const fileName of rootFileNames) this.fileVersions.set(fileName, 1) } } @@ -293,7 +293,7 @@ export function register (opts: Options = {}): Register { // Create the compiler host for type checking. const serviceHost: _ts.LanguageServiceHost = { - getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()), + getScriptFileNames: () => memoryCache.rootFileNames, getScriptVersion: (fileName: string) => { const version = memoryCache.fileVersions.get(fileName) return version === undefined ? '' : version.toString() @@ -332,6 +332,9 @@ export function register (opts: Options = {}): Register { const updateMemoryCache = (contents: string, fileName: string) => { const fileVersion = memoryCache.fileVersions.get(fileName) || 0 + // Add to `rootFiles` when discovered for the first time. + if (fileVersion === 0) memoryCache.rootFileNames.push(fileName) + // Avoid incrementing cache when nothing has changed. if (memoryCache.fileContents.get(fileName) === contents) return