diff options
author | Aapo Alasuutari <aapo.alasuutari@gmail.com> | 2022-08-11 16:56:56 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-11 15:56:56 +0200 |
commit | 2164f6b1eb7216c1045d547c94f26fe3ceaa9403 (patch) | |
tree | 056e3d6540ebd0e755650765adcff6b5cc173db8 /test_ffi/tests | |
parent | 883269f1f183428f60c54223135d8dd25977b3cd (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 'test_ffi/tests')
-rw-r--r-- | test_ffi/tests/bench.js | 4 | ||||
-rw-r--r-- | test_ffi/tests/test.js | 26 |
2 files changed, 15 insertions, 15 deletions
diff --git a/test_ffi/tests/bench.js b/test_ffi/tests/bench.js index 084615575..5342f84ff 100644 --- a/test_ffi/tests/bench.js +++ b/test_ffi/tests/bench.js @@ -337,6 +337,8 @@ Deno.bench("nop_f64()", () => { const { nop_buffer } = dylib.symbols; const buffer = new Uint8Array(8).fill(5); +// Make sure the buffer does not get collected +globalThis.buffer = buffer; Deno.bench("nop_buffer()", () => { nop_buffer(buffer); }); @@ -539,6 +541,8 @@ Deno.bench("return_buffer_nonblocking()", async () => { const { nop_many_parameters } = dylib.symbols; const buffer2 = new Uint8Array(8).fill(25); +// Make sure the buffer does not get collected +globalThis.buffer2 = buffer2; Deno.bench("nop_many_parameters()", () => { nop_many_parameters( 135, diff --git a/test_ffi/tests/test.js b/test_ffi/tests/test.js index 23b46902a..062dced76 100644 --- a/test_ffi/tests/test.js +++ b/test_ffi/tests/test.js @@ -18,10 +18,6 @@ const libPath = `${targetDir}/${libPrefix}test_ffi.${libSuffix}`; const resourcesPre = Deno.resources(); -function ptr(v) { - return Deno.UnsafePointer.of(v); -} - // dlopen shouldn't panic assertThrows(() => { Deno.dlopen("cli/src/main.rs", {}); @@ -420,7 +416,7 @@ const throwCallback = new Deno.UnsafeCallback({ assertThrows( () => { - dylib.symbols.call_fn_ptr(ptr(throwCallback)); + dylib.symbols.call_fn_ptr(throwCallback.pointer); }, TypeError, "hi", @@ -428,13 +424,13 @@ assertThrows( const { call_stored_function } = dylib.symbols; -dylib.symbols.call_fn_ptr(ptr(logCallback)); -dylib.symbols.call_fn_ptr_many_parameters(ptr(logManyParametersCallback)); -dylib.symbols.call_fn_ptr_return_u8(ptr(returnU8Callback)); -dylib.symbols.call_fn_ptr_return_buffer(ptr(returnBufferCallback)); -dylib.symbols.store_function(ptr(logCallback)); +dylib.symbols.call_fn_ptr(logCallback.pointer); +dylib.symbols.call_fn_ptr_many_parameters(logManyParametersCallback.pointer); +dylib.symbols.call_fn_ptr_return_u8(returnU8Callback.pointer); +dylib.symbols.call_fn_ptr_return_buffer(returnBufferCallback.pointer); +dylib.symbols.store_function(logCallback.pointer); call_stored_function(); -dylib.symbols.store_function_2(ptr(add10Callback)); +dylib.symbols.store_function_2(add10Callback.pointer); dylib.symbols.call_stored_function_2(20); const nestedCallback = new Deno.UnsafeCallback( @@ -443,7 +439,7 @@ const nestedCallback = new Deno.UnsafeCallback( dylib.symbols.call_stored_function_2(10); }, ); -dylib.symbols.store_function(ptr(nestedCallback)); +dylib.symbols.store_function(nestedCallback.pointer); dylib.symbols.store_function(null); dylib.symbols.store_function_2(null); @@ -457,14 +453,14 @@ const addToFooCallback = new Deno.UnsafeCallback({ // Test thread safe callbacks console.log("Thread safe call counter:", counter); addToFooCallback.ref(); -await dylib.symbols.call_fn_ptr_thread_safe(ptr(addToFooCallback)); +await dylib.symbols.call_fn_ptr_thread_safe(addToFooCallback.pointer); addToFooCallback.unref(); logCallback.ref(); -await dylib.symbols.call_fn_ptr_thread_safe(ptr(logCallback)); +await dylib.symbols.call_fn_ptr_thread_safe(logCallback.pointer); logCallback.unref(); console.log("Thread safe call counter:", counter); returnU8Callback.ref(); -await dylib.symbols.call_fn_ptr_return_u8_thread_safe(ptr(returnU8Callback)); +await dylib.symbols.call_fn_ptr_return_u8_thread_safe(returnU8Callback.pointer); // Test statics console.log("Static u32:", dylib.symbols.static_u32); |