Skip to content

Commit 87a6e2c

Browse files
committedSep 16, 2019
Revert "List all files in memory cache improves perf 1.4x"
This reverts commit 6dad5ad.
1 parent 3efdea4 commit 87a6e2c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed
 

‎src/index.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class MemoryCache {
8181
fileContents = new Map<string, string>()
8282
fileVersions = new Map<string, number>()
8383

84-
constructor (rootFileNames: string[] = []) {
84+
constructor (public rootFileNames: string[] = []) {
8585
for (const fileName of rootFileNames) this.fileVersions.set(fileName, 1)
8686
}
8787
}
@@ -293,7 +293,7 @@ export function register (opts: Options = {}): Register {
293293

294294
// Create the compiler host for type checking.
295295
const serviceHost: _ts.LanguageServiceHost = {
296-
getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
296+
getScriptFileNames: () => memoryCache.rootFileNames,
297297
getScriptVersion: (fileName: string) => {
298298
const version = memoryCache.fileVersions.get(fileName)
299299
return version === undefined ? '' : version.toString()
@@ -332,6 +332,9 @@ export function register (opts: Options = {}): Register {
332332
const updateMemoryCache = (contents: string, fileName: string) => {
333333
const fileVersion = memoryCache.fileVersions.get(fileName) || 0
334334

335+
// Add to `rootFiles` when discovered for the first time.
336+
if (fileVersion === 0) memoryCache.rootFileNames.push(fileName)
337+
335338
// Avoid incrementing cache when nothing has changed.
336339
if (memoryCache.fileContents.get(fileName) === contents) return
337340

0 commit comments

Comments
 (0)
Please sign in to comment.