diff options
author | Nayeem Rahman <nayeemrmn99@gmail.com> | 2024-04-08 22:20:20 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-08 22:20:20 +0100 |
commit | 214bfa37aa41de05f264bee0c2365a7df2098282 (patch) | |
tree | c751a55e2caa292e8e1c0123b1f3bb3c3cb1fdf7 /cli/tsc | |
parent | d3b63bb315c7573974d8bd79dcfb6849cb29cf4e (diff) |
perf(lsp): cache ts config in isolate until new project version (#23283)
Diffstat (limited to 'cli/tsc')
-rw-r--r-- | cli/tsc/99_main_compiler.js | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js index 3408b0f07..ef1077af8 100644 --- a/cli/tsc/99_main_compiler.js +++ b/cli/tsc/99_main_compiler.js @@ -162,6 +162,19 @@ delete Object.prototype.__proto__; const isCjsCache = new SpecifierIsCjsCache(); + /** @type {ts.CompilerOptions | null} */ + let tsConfigCache = null; + /** @type {string | null} */ + let tsConfigCacheProjectVersion = null; + + /** @type {string | null} */ + let projectVersionCache = null; + /** @type {number | null} */ + let projectVersionCacheLastRequestId = null; + + /** @type {number | null} */ + let lastRequestId = null; + /** * @param {ts.CompilerOptions | ts.MinimalResolutionCacheHost} settingsOrHost * @returns {ts.CompilerOptions} @@ -531,7 +544,15 @@ delete Object.prototype.__proto__; return new CancellationToken(); }, getProjectVersion() { - return ops.op_project_version(); + if ( + projectVersionCache && projectVersionCacheLastRequestId == lastRequestId + ) { + return projectVersionCache; + } + const projectVersion = ops.op_project_version(); + projectVersionCache = projectVersion; + projectVersionCacheLastRequestId = lastRequestId; + return projectVersion; }, // @ts-ignore Undocumented method. getModuleSpecifierCache() { @@ -730,6 +751,10 @@ delete Object.prototype.__proto__; if (logDebug) { debug("host.getCompilationSettings()"); } + const projectVersion = this.getProjectVersion(); + if (tsConfigCache && tsConfigCacheProjectVersion == projectVersion) { + return tsConfigCache; + } const tsConfig = normalizeConfig(ops.op_ts_config()); const { options, errors } = ts .convertCompilerOptionsFromJson(tsConfig, ""); @@ -740,6 +765,8 @@ delete Object.prototype.__proto__; if (errors.length > 0 && logDebug) { debug(ts.formatDiagnostics(errors, host)); } + tsConfigCache = options; + tsConfigCacheProjectVersion = projectVersion; return options; }, getScriptFileNames() { @@ -1020,7 +1047,7 @@ delete Object.prototype.__proto__; if (logDebug) { debug(`serverRequest()`, id, method, args); } - + lastRequestId = id; // reset all memoized source files names scriptFileNamesCache = undefined; // evict all memoized source file versions |