Skip to content

Commit

Permalink
List all files in memory cache improves perf 1.4x
Browse files Browse the repository at this point in the history
  • Loading branch information
blakeembrey committed May 26, 2019
1 parent cd977fd commit 6dad5ad
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class MemoryCache {
fileContents = new Map<string, string>()
fileVersions = new Map<string, number>()

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

// Create the compiler host for type checking.
const serviceHost: _ts.LanguageServiceHost = {
getScriptFileNames: () => memoryCache.rootFileNames,
getScriptFileNames: () => Array.from(memoryCache.fileVersions.keys()),
getScriptVersion: (fileName: string) => {
const version = memoryCache.fileVersions.get(fileName)
return version === undefined ? '' : version.toString()
Expand Down Expand Up @@ -335,9 +335,6 @@ export function register (opts: Options = {}): Register {
const updateMemoryCache = function (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 6dad5ad

Please sign in to comment.