Skip to content

Commit

Permalink
Revert "List all files in memory cache improves perf 1.4x"
Browse files Browse the repository at this point in the history
This reverts commit 6dad5ad.
  • Loading branch information
blakeembrey committed Sep 16, 2019
1 parent 3efdea4 commit 87a6e2c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/index.ts
Expand Up @@ -81,7 +81,7 @@ class MemoryCache {
fileContents = new Map<string, string>()
fileVersions = new Map<string, number>()

constructor (rootFileNames: string[] = []) {
constructor (public rootFileNames: string[] = []) {
for (const fileName of rootFileNames) this.fileVersions.set(fileName, 1)
}
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 87a6e2c

Please sign in to comment.