mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 17:34:47 -05:00
perf(lsp): cache ts config in isolate until new project version (#23283)
This commit is contained in:
parent
d3b63bb315
commit
214bfa37aa
1 changed files with 29 additions and 2 deletions
|
@ -162,6 +162,19 @@ delete Object.prototype.__proto__;
|
||||||
|
|
||||||
const isCjsCache = new SpecifierIsCjsCache();
|
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
|
* @param {ts.CompilerOptions | ts.MinimalResolutionCacheHost} settingsOrHost
|
||||||
* @returns {ts.CompilerOptions}
|
* @returns {ts.CompilerOptions}
|
||||||
|
@ -531,7 +544,15 @@ delete Object.prototype.__proto__;
|
||||||
return new CancellationToken();
|
return new CancellationToken();
|
||||||
},
|
},
|
||||||
getProjectVersion() {
|
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.
|
// @ts-ignore Undocumented method.
|
||||||
getModuleSpecifierCache() {
|
getModuleSpecifierCache() {
|
||||||
|
@ -730,6 +751,10 @@ delete Object.prototype.__proto__;
|
||||||
if (logDebug) {
|
if (logDebug) {
|
||||||
debug("host.getCompilationSettings()");
|
debug("host.getCompilationSettings()");
|
||||||
}
|
}
|
||||||
|
const projectVersion = this.getProjectVersion();
|
||||||
|
if (tsConfigCache && tsConfigCacheProjectVersion == projectVersion) {
|
||||||
|
return tsConfigCache;
|
||||||
|
}
|
||||||
const tsConfig = normalizeConfig(ops.op_ts_config());
|
const tsConfig = normalizeConfig(ops.op_ts_config());
|
||||||
const { options, errors } = ts
|
const { options, errors } = ts
|
||||||
.convertCompilerOptionsFromJson(tsConfig, "");
|
.convertCompilerOptionsFromJson(tsConfig, "");
|
||||||
|
@ -740,6 +765,8 @@ delete Object.prototype.__proto__;
|
||||||
if (errors.length > 0 && logDebug) {
|
if (errors.length > 0 && logDebug) {
|
||||||
debug(ts.formatDiagnostics(errors, host));
|
debug(ts.formatDiagnostics(errors, host));
|
||||||
}
|
}
|
||||||
|
tsConfigCache = options;
|
||||||
|
tsConfigCacheProjectVersion = projectVersion;
|
||||||
return options;
|
return options;
|
||||||
},
|
},
|
||||||
getScriptFileNames() {
|
getScriptFileNames() {
|
||||||
|
@ -1020,7 +1047,7 @@ delete Object.prototype.__proto__;
|
||||||
if (logDebug) {
|
if (logDebug) {
|
||||||
debug(`serverRequest()`, id, method, args);
|
debug(`serverRequest()`, id, method, args);
|
||||||
}
|
}
|
||||||
|
lastRequestId = id;
|
||||||
// reset all memoized source files names
|
// reset all memoized source files names
|
||||||
scriptFileNamesCache = undefined;
|
scriptFileNamesCache = undefined;
|
||||||
// evict all memoized source file versions
|
// evict all memoized source file versions
|
||||||
|
|
Loading…
Add table
Reference in a new issue