summaryrefslogtreecommitdiff
path: root/ext/node/01_require.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 /ext/node/01_require.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 'ext/node/01_require.js')
-rw-r--r--ext/node/01_require.js34
1 files changed, 16 insertions, 18 deletions
diff --git a/ext/node/01_require.js b/ext/node/01_require.js
index 7b89e9dc3..ccccb8578 100644
--- a/ext/node/01_require.js
+++ b/ext/node/01_require.js
@@ -31,16 +31,17 @@
RegExpPrototypeTest,
} = window.__bootstrap.primordials;
const core = window.Deno.core;
+ const ops = core.ops;
// Map used to store CJS parsing data.
const cjsParseCache = new SafeWeakMap();
function pathDirname(filepath) {
- return core.opSync("op_require_path_dirname", filepath);
+ return ops.op_require_path_dirname(filepath);
}
function pathResolve(...args) {
- return core.opSync("op_require_path_resolve", args);
+ return ops.op_require_path_resolve(args);
}
function assert(cond) {
@@ -76,7 +77,7 @@
return result;
}
}
- const result = core.opSync("op_require_stat", filename);
+ const result = ops.op_require_stat(filename);
if (statCache !== null && result >= 0) {
statCache.set(filename, result);
}
@@ -162,7 +163,7 @@
if (maybeCached) {
return maybeCached;
}
- const rp = core.opSync("op_require_real_path", requestPath);
+ const rp = ops.op_require_real_path(requestPath);
realpathCache.set(requestPath, rp);
return rp;
}
@@ -181,7 +182,7 @@
// Find the longest (possibly multi-dot) extension registered in
// Module._extensions
function findLongestRegisteredExtension(filename) {
- const name = core.opSync("op_require_path_basename", filename);
+ const name = ops.op_require_path_basename(filename);
let currentExtension;
let index;
let startIndex = 0;
@@ -269,7 +270,7 @@
const CHAR_FORWARD_SLASH = 47;
const TRAILING_SLASH_REGEX = /(?:^|\/)\.?\.$/;
Module._findPath = function (request, paths, isMain) {
- const absoluteRequest = core.opSync("op_require_path_is_absolute", request);
+ const absoluteRequest = ops.op_require_path_is_absolute(request);
if (absoluteRequest) {
paths = [""];
} else if (!paths || paths.length === 0) {
@@ -346,12 +347,11 @@
};
Module._nodeModulePaths = function (from) {
- return core.opSync("op_require_node_module_paths", from);
+ return ops.op_require_node_module_paths(from);
};
Module._resolveLookupPaths = function (request, parent) {
- return core.opSync(
- "op_require_resolve_lookup_paths",
+ return ops.op_require_resolve_lookup_paths(
request,
parent?.paths,
parent?.filename ?? "",
@@ -475,8 +475,7 @@
if (typeof options === "object" && options !== null) {
if (ArrayIsArray(options.paths)) {
- const isRelative = core.opSync(
- "op_require_is_request_relative",
+ const isRelative = ops.op_require_is_request_relative(
request,
);
@@ -537,13 +536,12 @@
// Try module self resolution first
// TODO(bartlomieju): make into a single op
- const parentPath = core.opSync(
- "op_require_try_self_parent_path",
+ const parentPath = ops.op_require_try_self_parent_path(
!!parent,
parent?.filename,
parent?.id,
);
- // const selfResolved = core.opSync("op_require_try_self", parentPath, request);
+ // const selfResolved = ops.op_require_try_self(parentPath, request);
const selfResolved = false;
if (selfResolved) {
const cacheKey = request + "\x00" +
@@ -666,7 +664,7 @@
};
Module._extensions[".js"] = function (module, filename) {
- const content = core.opSync("op_require_read_file", filename);
+ const content = ops.op_require_read_file(filename);
console.log(`TODO: Module._extensions[".js"] is ESM`);
@@ -682,7 +680,7 @@
// Native extension for .json
Module._extensions[".json"] = function (module, filename) {
- const content = core.opSync("op_require_read_file", filename);
+ const content = ops.op_require_read_file(filename);
try {
module.exports = JSONParse(stripBOM(content));
@@ -698,7 +696,7 @@
};
function createRequireFromPath(filename) {
- const proxyPath = core.opSync("op_require_proxy_path", filename);
+ const proxyPath = ops.op_require_proxy_path(filename);
const mod = new Module(proxyPath);
mod.filename = proxyPath;
mod.paths = Module._nodeModulePaths(mod.path);
@@ -737,7 +735,7 @@
Module.createRequire = createRequire;
Module._initPaths = function () {
- const paths = core.opSync("op_require_init_paths");
+ const paths = ops.op_require_init_paths();
modulePaths = paths;
Module.globalPaths = ArrayPrototypeSlice(modulePaths);
};