Skip to content

Commit 6dad5ad

Browse files
committed
List all files in memory cache improves perf 1.4x
1 parent cd977fd commit 6dad5ad

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class MemoryCache {
8080
fileContents = new Map<string, string>()
8181
fileVersions = new Map<string, number>()
8282

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

297297
// Create the compiler host for type checking.
298298
const serviceHost: _ts.LanguageServiceHost = {
299-
getScriptFileNames: () => memoryCache.rootFileNames,
299+
getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
300300
getScriptVersion: (fileName: string) => {
301301
const version = memoryCache.fileVersions.get(fileName)
302302
return version === undefined ? '' : version.toString()
@@ -335,9 +335,6 @@ export function register (opts: Options = {}): Register {
335335
const updateMemoryCache = function (contents: string, fileName: string) {
336336
const fileVersion = memoryCache.fileVersions.get(fileName) || 0
337337

338-
// Add to `rootFiles` when discovered for the first time.
339-
if (fileVersion === 0) memoryCache.rootFileNames.push(fileName)
340-
341338
// Avoid incrementing cache when nothing has changed.
342339
if (memoryCache.fileContents.get(fileName) === contents) return
343340

0 commit comments

Comments
 (0)