Skip to content

Commit

Permalink
Merge pull request #1049 from topaxi/use-lodash-memoize
Browse files Browse the repository at this point in the history
fix(perf): add cache for fs calls when using language service
  • Loading branch information
kulshekhar authored Sep 9, 2019
2 parents 1e40cb1 + 5e28040 commit be3731c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 76 deletions.
83 changes: 14 additions & 69 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"bs-logger": "0.x",
"buffer-from": "1.x",
"fast-json-stable-stringify": "2.x",
"lodash.memoize": "4.x",
"json5": "2.x",
"make-error": "1.x",
"mkdirp": "0.x",
Expand Down Expand Up @@ -103,7 +104,6 @@
"jest": "24.x",
"js-yaml": "latest",
"lint-staged": "latest",
"lodash.memoize": "4.x",
"lodash.merge": "4.x",
"lodash.set": "4.x",
"npm-run-all": "latest",
Expand Down
14 changes: 8 additions & 6 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { LogContexts, LogLevels, Logger } from 'bs-logger'
import bufferFrom = require('buffer-from')
import stableStringify = require('fast-json-stable-stringify')
import { readFileSync, writeFileSync } from 'fs'
import memoize = require('lodash.memoize')
import mkdirp = require('mkdirp')
import { basename, extname, join, relative } from 'path'

Expand Down Expand Up @@ -131,6 +132,7 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
...serviceHostDebugCtx,
[LogContexts.logLevel]: LogLevels.trace,
}

const serviceHost = {
getScriptFileNames: () => Object.keys(memoryCache.versions),
getScriptVersion: (fileName: string) => {
Expand All @@ -157,12 +159,12 @@ export function createCompiler(configs: ConfigSet): TsCompiler {
}
return ts.ScriptSnapshot.fromString(contents)
},
fileExists: ts.sys.fileExists,
readFile: logger.wrap(serviceHostTraceCtx, 'readFile', ts.sys.readFile),
readDirectory: ts.sys.readDirectory,
getDirectories: ts.sys.getDirectories,
directoryExists: ts.sys.directoryExists,
realpath: ts.sys.realpath,
fileExists: memoize(ts.sys.fileExists),
readFile: logger.wrap(serviceHostTraceCtx, 'readFile', memoize(ts.sys.readFile)),
readDirectory: memoize(ts.sys.readDirectory),
getDirectories: memoize(ts.sys.getDirectories),
directoryExists: memoize(ts.sys.directoryExists),
realpath: memoize(ts.sys.realpath!),
getNewLine: () => '\n',
getCurrentDirectory: () => cwd,
getCompilationSettings: () => compilerOptions,
Expand Down

0 comments on commit be3731c

Please sign in to comment.