Skip to content

Commit be3731c

Browse files
authored
Merge pull request #1049 from topaxi/use-lodash-memoize
fix(perf): add cache for fs calls when using language service
2 parents 1e40cb1 + 5e28040 commit be3731c

File tree

3 files changed

+23
-76
lines changed

3 files changed

+23
-76
lines changed

package-lock.json

Lines changed: 14 additions & 69 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"bs-logger": "0.x",
6060
"buffer-from": "1.x",
6161
"fast-json-stable-stringify": "2.x",
62+
"lodash.memoize": "4.x",
6263
"json5": "2.x",
6364
"make-error": "1.x",
6465
"mkdirp": "0.x",
@@ -103,7 +104,6 @@
103104
"jest": "24.x",
104105
"js-yaml": "latest",
105106
"lint-staged": "latest",
106-
"lodash.memoize": "4.x",
107107
"lodash.merge": "4.x",
108108
"lodash.set": "4.x",
109109
"npm-run-all": "latest",

src/compiler.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import { LogContexts, LogLevels, Logger } from 'bs-logger'
3333
import bufferFrom = require('buffer-from')
3434
import stableStringify = require('fast-json-stable-stringify')
3535
import { readFileSync, writeFileSync } from 'fs'
36+
import memoize = require('lodash.memoize')
3637
import mkdirp = require('mkdirp')
3738
import { basename, extname, join, relative } from 'path'
3839

@@ -131,6 +132,7 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
131132
...serviceHostDebugCtx,
132133
[LogContexts.logLevel]: LogLevels.trace,
133134
}
135+
134136
const serviceHost = {
135137
getScriptFileNames: () => Object.keys(memoryCache.versions),
136138
getScriptVersion: (fileName: string) => {
@@ -157,12 +159,12 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
157159
}
158160
return ts.ScriptSnapshot.fromString(contents)
159161
},
160-
fileExists: ts.sys.fileExists,
161-
readFile: logger.wrap(serviceHostTraceCtx, 'readFile', ts.sys.readFile),
162-
readDirectory: ts.sys.readDirectory,
163-
getDirectories: ts.sys.getDirectories,
164-
directoryExists: ts.sys.directoryExists,
165-
realpath: ts.sys.realpath,
162+
fileExists: memoize(ts.sys.fileExists),
163+
readFile: logger.wrap(serviceHostTraceCtx, 'readFile', memoize(ts.sys.readFile)),
164+
readDirectory: memoize(ts.sys.readDirectory),
165+
getDirectories: memoize(ts.sys.getDirectories),
166+
directoryExists: memoize(ts.sys.directoryExists),
167+
realpath: memoize(ts.sys.realpath!),
166168
getNewLine: () => '\n',
167169
getCurrentDirectory: () => cwd,
168170
getCompilationSettings: () => compilerOptions,

0 commit comments

Comments
 (0)