summaryrefslogtreecommitdiff
path: root/core/runtime.rs
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 /core/runtime.rs
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 'core/runtime.rs')
-rw-r--r--core/runtime.rs78
1 files changed, 39 insertions, 39 deletions
diff --git a/core/runtime.rs b/core/runtime.rs
index 3f3caac5e..541aa7c02 100644
--- a/core/runtime.rs
+++ b/core/runtime.rs
@@ -2301,8 +2301,8 @@ pub mod tests {
.execute_script(
"filename.js",
r#"
- Deno.core.opSync("op_unref_op", p1[promiseIdSymbol]);
- Deno.core.opSync("op_unref_op", p2[promiseIdSymbol]);
+ Deno.core.ops.op_unref_op(p1[promiseIdSymbol]);
+ Deno.core.ops.op_unref_op(p2[promiseIdSymbol]);
"#,
)
.unwrap();
@@ -2317,8 +2317,8 @@ pub mod tests {
.execute_script(
"filename.js",
r#"
- Deno.core.opSync("op_ref_op", p1[promiseIdSymbol]);
- Deno.core.opSync("op_ref_op", p2[promiseIdSymbol]);
+ Deno.core.ops.op_ref_op(p1[promiseIdSymbol]);
+ Deno.core.ops.op_ref_op(p2[promiseIdSymbol]);
"#,
)
.unwrap();
@@ -3045,7 +3045,7 @@ assertEquals(1, notify_return_value);
let error = runtime
.execute_script(
"core_js_stack_frame.js",
- "Deno.core.opSync('non_existent');",
+ "Deno.core.opAsync('non_existent');",
)
.unwrap_err();
let error_string = error.to_string();
@@ -3073,7 +3073,7 @@ assertEquals(1, notify_return_value);
(function () {
const o = { a: 1, b: 2};
const p = new Proxy(o, {});
- return Deno.core.opSync("op_is_proxy", p) && !Deno.core.opSync("op_is_proxy", o) && !Deno.core.opSync("op_is_proxy", 42);
+ return Deno.core.ops.op_is_proxy(p) && !Deno.core.ops.op_is_proxy(o) && !Deno.core.ops.op_is_proxy(42);
})()
"#,
)
@@ -3150,16 +3150,16 @@ assertEquals(1, notify_return_value);
r#"
(async function () {
const results = [];
- Deno.core.opSync("op_set_macrotask_callback", () => {
+ Deno.core.ops.op_set_macrotask_callback(() => {
results.push("macrotask");
return true;
});
- Deno.core.opSync("op_set_next_tick_callback", () => {
+ Deno.core.ops.op_set_next_tick_callback(() => {
results.push("nextTick");
- Deno.core.opSync("op_set_has_tick_scheduled", false);
+ Deno.core.ops.op_set_has_tick_scheduled(false);
});
- Deno.core.opSync("op_set_has_tick_scheduled", true);
+ Deno.core.ops.op_set_has_tick_scheduled(true);
await Deno.core.opAsync('op_async_sleep');
if (results[0] != "nextTick") {
throw new Error(`expected nextTick, got: ${results[0]}`);
@@ -3182,10 +3182,10 @@ assertEquals(1, notify_return_value);
.execute_script(
"multiple_macrotasks_and_nextticks.js",
r#"
- Deno.core.opSync("op_set_macrotask_callback", () => { return true; });
- Deno.core.opSync("op_set_macrotask_callback", () => { return true; });
- Deno.core.opSync("op_set_next_tick_callback", () => {});
- Deno.core.opSync("op_set_next_tick_callback", () => {});
+ Deno.core.ops.op_set_macrotask_callback(() => { return true; });
+ Deno.core.ops.op_set_macrotask_callback(() => { return true; });
+ Deno.core.ops.op_set_next_tick_callback(() => {});
+ Deno.core.ops.op_set_next_tick_callback(() => {});
"#,
)
.unwrap();
@@ -3228,12 +3228,12 @@ assertEquals(1, notify_return_value);
.execute_script(
"has_tick_scheduled.js",
r#"
- Deno.core.opSync("op_set_macrotask_callback", () => {
- Deno.core.opSync("op_macrotask");
+ Deno.core.ops.op_set_macrotask_callback(() => {
+ Deno.core.ops.op_macrotask();
return true; // We're done.
});
- Deno.core.opSync("op_set_next_tick_callback", () => Deno.core.opSync("op_next_tick"));
- Deno.core.opSync("op_set_has_tick_scheduled", true);
+ Deno.core.ops.op_set_next_tick_callback(() => Deno.core.ops.op_next_tick());
+ Deno.core.ops.op_set_has_tick_scheduled(true);
"#,
)
.unwrap();
@@ -3359,15 +3359,15 @@ assertEquals(1, notify_return_value);
"promise_reject_callback.js",
r#"
// Note: |promise| is not the promise created below, it's a child.
- Deno.core.opSync("op_set_promise_reject_callback", (type, promise, reason) => {
+ Deno.core.ops.op_set_promise_reject_callback((type, promise, reason) => {
if (type !== /* PromiseRejectWithNoHandler */ 0) {
throw Error("unexpected type: " + type);
}
if (reason.message !== "reject") {
throw Error("unexpected reason: " + reason);
}
- Deno.core.opSync("op_store_pending_promise_exception", promise);
- Deno.core.opSync("op_promise_reject");
+ Deno.core.ops.op_store_pending_promise_exception(promise);
+ Deno.core.ops.op_promise_reject();
});
new Promise((_, reject) => reject(Error("reject")));
@@ -3383,7 +3383,7 @@ assertEquals(1, notify_return_value);
"promise_reject_callback.js",
r#"
{
- const prev = Deno.core.opSync("op_set_promise_reject_callback", (...args) => {
+ const prev = Deno.core.ops.op_set_promise_reject_callback((...args) => {
prev(...args);
});
}
@@ -3434,10 +3434,10 @@ assertEquals(1, notify_return_value);
_is_dyn_import: bool,
) -> Pin<Box<ModuleSourceFuture>> {
let source = r#"
- Deno.core.opSync("op_set_promise_reject_callback", (type, promise, reason) => {
- Deno.core.opSync("op_promise_reject");
+ Deno.core.ops.op_set_promise_reject_callback((type, promise, reason) => {
+ Deno.core.ops.op_promise_reject();
});
-
+
throw new Error('top level throw');
"#;
@@ -3485,7 +3485,7 @@ assertEquals(1, notify_return_value);
assert!(runtime
.execute_script(
"test_op_return_serde_v8_error.js",
- "Deno.core.opSync('op_err')"
+ "Deno.core.ops.op_err()"
)
.is_err());
}
@@ -3508,7 +3508,7 @@ assertEquals(1, notify_return_value);
..Default::default()
});
let r = runtime
- .execute_script("test.js", "Deno.core.opSync('op_add_4', 1, 2, 3, 4)")
+ .execute_script("test.js", "Deno.core.ops.op_add_4(1, 2, 3, 4)")
.unwrap();
let scope = &mut runtime.handle_scope();
assert_eq!(r.open(scope).integer_value(scope), Some(10));
@@ -3529,7 +3529,7 @@ assertEquals(1, notify_return_value);
..Default::default()
});
let r = runtime
- .execute_script("test.js", "Deno.core.opSync('op_foo')")
+ .execute_script("test.js", "Deno.core.ops.op_foo()")
.unwrap();
let scope = &mut runtime.handle_scope();
assert!(r.open(scope).is_undefined());
@@ -3573,7 +3573,7 @@ assertEquals(1, notify_return_value);
if (!(a1.length > 0 && a1b.length > 0)) {
throw new Error("a1 & a1b should have a length");
}
- let sum = Deno.core.opSync('op_sum_take', a1b);
+ let sum = Deno.core.ops.op_sum_take(a1b);
if (sum !== 6) {
throw new Error(`Bad sum: ${sum}`);
}
@@ -3581,7 +3581,7 @@ assertEquals(1, notify_return_value);
throw new Error("expecting a1 & a1b to be detached");
}
- const a3 = Deno.core.opSync('op_boomerang', a2b);
+ const a3 = Deno.core.ops.op_boomerang(a2b);
if (a3.byteLength != 3) {
throw new Error(`Expected a3.byteLength === 3, got ${a3.byteLength}`);
}
@@ -3597,7 +3597,7 @@ assertEquals(1, notify_return_value);
w32[0] = 1; w32[1] = 2; w32[2] = 3;
const assertWasmThrow = (() => {
try {
- let sum = Deno.core.opSync('op_sum_take', w32.subarray(0, 2));
+ let sum = Deno.core.ops.op_sum_take(w32.subarray(0, 2));
return false;
} catch(e) {
return e.message.includes('ExpectedDetachable');
@@ -3635,10 +3635,10 @@ assertEquals(1, notify_return_value);
.execute_script(
"test.js",
r#"
- if (Deno.core.opSync('op_foo') !== 42) {
+ if (Deno.core.ops.op_foo() !== 42) {
throw new Error("Exptected op_foo() === 42");
}
- if (Deno.core.opSync('op_bar') !== undefined) {
+ if (Deno.core.ops.op_bar() !== undefined) {
throw new Error("Expected op_bar to be disabled")
}
"#,
@@ -3680,7 +3680,7 @@ assertEquals(1, notify_return_value);
});
let realm = runtime.create_realm().unwrap();
let ret = realm
- .execute_script(runtime.v8_isolate(), "", "Deno.core.opSync('op_test')")
+ .execute_script(runtime.v8_isolate(), "", "Deno.core.ops.op_test()")
.unwrap();
let scope = &mut realm.handle_scope(runtime.v8_isolate());
@@ -3710,7 +3710,7 @@ assertEquals(1, notify_return_value);
});
let realm = runtime.create_realm().unwrap();
let ret = realm
- .execute_script(runtime.v8_isolate(), "", "Deno.core.opSync('op_test')")
+ .execute_script(runtime.v8_isolate(), "", "Deno.core.ops.op_test()")
.unwrap();
let scope = &mut realm.handle_scope(runtime.v8_isolate());
@@ -3749,10 +3749,10 @@ assertEquals(1, notify_return_value);
runtime.v8_isolate(),
"",
r#"
- const buf = Deno.core.opSync("op_test", false);
+ const buf = Deno.core.ops.op_test(false);
let err;
try {
- Deno.core.opSync("op_test", true);
+ Deno.core.ops.op_test(true);
} catch(e) {
err = e;
}
@@ -3870,7 +3870,7 @@ assertEquals(1, notify_return_value);
"",
r#"
let promiseIdSymbol = Symbol.for("Deno.core.internalPromiseId");
- Deno.core.opSync("op_unref_op", promise[promiseIdSymbol]);
+ Deno.core.ops.op_unref_op(promise[promiseIdSymbol]);
"#,
)
.unwrap();
@@ -3882,7 +3882,7 @@ assertEquals(1, notify_return_value);
"",
r#"
let promiseIdSymbol = Symbol.for("Deno.core.internalPromiseId");
- Deno.core.opSync("op_unref_op", promise[promiseIdSymbol]);
+ Deno.core.ops.op_unref_op(promise[promiseIdSymbol]);
"#,
)
.unwrap();