summaryrefslogtreecommitdiff
path: root/cli/tsc/99_main_compiler.js
diff options
context:
space:
mode:
authorAapo Alasuutari <aapo.alasuutari@gmail.com>2022-08-11 16:56:56 +0300
committerGitHub <noreply@github.com>2022-08-11 15:56:56 +0200
commit2164f6b1eb7216c1045d547c94f26fe3ceaa9403 (patch)
tree056e3d6540ebd0e755650765adcff6b5cc173db8 /cli/tsc/99_main_compiler.js
parent883269f1f183428f60c54223135d8dd25977b3cd (diff)
perf(ops): Monomorphic sync op calls (#15337)
Welcome to better optimised op calls! Currently opSync is called with parameters of every type and count. This most definitely makes the call megamorphic. Additionally, it seems that spread params leads to V8 not being able to optimise the calls quite as well (apparently Fast Calls cannot be used with spread params). Monomorphising op calls should lead to some improved performance. Now that unwrapping of sync ops results is done on Rust side, this is pretty simple: ``` opSync("op_foo", param1, param2); // -> turns to ops.op_foo(param1, param2); ``` This means sync op calls are now just directly calling the native binding function. When V8 Fast API Calls are enabled, this will enable those to be called on the optimised path. Monomorphising async ops likely requires using callbacks and is left as an exercise to the reader.
Diffstat (limited to 'cli/tsc/99_main_compiler.js')
-rw-r--r--cli/tsc/99_main_compiler.js32
1 files changed, 15 insertions, 17 deletions
diff --git a/cli/tsc/99_main_compiler.js b/cli/tsc/99_main_compiler.js
index b1d62348b..ab43af38d 100644
--- a/cli/tsc/99_main_compiler.js
+++ b/cli/tsc/99_main_compiler.js
@@ -15,6 +15,7 @@ delete Object.prototype.__proto__;
((window) => {
/** @type {DenoCore} */
const core = window.Deno.core;
+ const ops = core.ops;
let logDebug = false;
let logSource = "JS";
@@ -250,7 +251,7 @@ delete Object.prototype.__proto__;
}
this.#lastCheckTimeMs = timeMs;
- return core.opSync("op_is_cancelled", {});
+ return ops.op_is_cancelled();
}
throwIfCancellationRequested() {
@@ -274,11 +275,11 @@ delete Object.prototype.__proto__;
fileExists(specifier) {
debug(`host.fileExists("${specifier}")`);
specifier = normalizedToOriginalMap.get(specifier) ?? specifier;
- return core.opSync("op_exists", { specifier });
+ return ops.op_exists({ specifier });
},
readFile(specifier) {
debug(`host.readFile("${specifier}")`);
- return core.opSync("op_load", { specifier }).data;
+ return ops.op_load({ specifier }).data;
},
getCancellationToken() {
// createLanguageService will call this immediately and cache it
@@ -309,8 +310,7 @@ delete Object.prototype.__proto__;
}
/** @type {{ data: string; scriptKind: ts.ScriptKind; version: string; }} */
- const { data, scriptKind, version } = core.opSync(
- "op_load",
+ const { data, scriptKind, version } = ops.op_load(
{ specifier },
);
assert(
@@ -338,14 +338,13 @@ delete Object.prototype.__proto__;
},
writeFile(fileName, data, _writeByteOrderMark, _onError, _sourceFiles) {
debug(`host.writeFile("${fileName}")`);
- return core.opSync(
- "op_emit",
+ return ops.op_emit(
{ fileName, data },
);
},
getCurrentDirectory() {
debug(`host.getCurrentDirectory()`);
- return cwd ?? core.opSync("op_cwd", null);
+ return cwd ?? ops.op_cwd();
},
getCanonicalFileName(fileName) {
return fileName;
@@ -361,7 +360,7 @@ delete Object.prototype.__proto__;
debug(` base: ${base}`);
debug(` specifiers: ${specifiers.join(", ")}`);
/** @type {Array<[string, ts.Extension] | undefined>} */
- const resolved = core.opSync("op_resolve", {
+ const resolved = ops.op_resolve({
specifiers,
base,
});
@@ -384,7 +383,7 @@ delete Object.prototype.__proto__;
}
},
createHash(data) {
- return core.opSync("op_create_hash", { data }).hash;
+ return ops.op_create_hash({ data }).hash;
},
// LanguageServiceHost
@@ -399,7 +398,7 @@ delete Object.prototype.__proto__;
if (scriptFileNamesCache) {
return scriptFileNamesCache;
}
- return scriptFileNamesCache = core.opSync("op_script_names", undefined);
+ return scriptFileNamesCache = ops.op_script_names();
},
getScriptVersion(specifier) {
debug(`host.getScriptVersion("${specifier}")`);
@@ -412,7 +411,7 @@ delete Object.prototype.__proto__;
if (scriptVersionCache.has(specifier)) {
return scriptVersionCache.get(specifier);
}
- const scriptVersion = core.opSync("op_script_version", { specifier });
+ const scriptVersion = ops.op_script_version({ specifier });
scriptVersionCache.set(specifier, scriptVersion);
return scriptVersion;
},
@@ -433,8 +432,7 @@ delete Object.prototype.__proto__;
};
}
- const fileInfo = core.opSync(
- "op_load",
+ const fileInfo = ops.op_load(
{ specifier },
);
if (fileInfo) {
@@ -567,7 +565,7 @@ delete Object.prototype.__proto__;
performanceProgram({ program });
- core.opSync("op_respond", {
+ ops.op_respond({
diagnostics: fromTypeScriptDiagnostic(diagnostics),
stats: performanceEnd(),
});
@@ -579,7 +577,7 @@ delete Object.prototype.__proto__;
* @param {any} data
*/
function respond(id, data = null) {
- core.opSync("op_respond", { id, data });
+ ops.op_respond({ id, data });
}
/**
@@ -942,7 +940,7 @@ delete Object.prototype.__proto__;
// ensure the snapshot is setup properly.
/** @type {{ buildSpecifier: string; libs: string[] }} */
- const { buildSpecifier, libs } = core.opSync("op_build_info", {});
+ const { buildSpecifier, libs } = ops.op_build_info();
for (const lib of libs) {
const specifier = `lib.${lib}.d.ts`;
// we are using internal APIs here to "inject" our custom libraries into