deno/ext/ffi
Aapo Alasuutari 2164f6b1eb
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.
2022-08-11 15:56:56 +02:00
..
tinycc@afc136262e fix(ext/ffi): trampoline for fast calls (#15139) 2022-07-12 06:33:05 +05:30
00_ffi.js perf(ops): Monomorphic sync op calls (#15337) 2022-08-11 15:56:56 +02:00
build.rs chore: fix Windows specific clippy errors (#15212) 2022-07-15 12:30:25 -04:00
Cargo.toml chore: forward v1.24.2 release commit to main (#15410) 2022-08-05 00:10:47 +02:00
jit_trampoline.rs perf(ext/ffi): use fast api calls for 64bit return types (#15313) 2022-07-28 18:08:22 +05:30
lib.rs fix(ext/ffi): unstable op_ffi_unsafe_callback_ref (#15439) 2022-08-10 08:39:45 +05:30
prelude.h perf(ext/ffi): support Uint8Array in fast calls (#15319) 2022-07-27 19:32:21 +05:30
README.md fix(ext/ffi): trampoline for fast calls (#15139) 2022-07-12 06:33:05 +05:30
tcc.rs chore(ext/ffi): remove flaky test (#15426) 2022-08-08 22:45:24 +05:30

deno_ffi

This crate implements dynamic library ffi.

Performance

Deno FFI calls have extremely low overhead (~1ns on M1 16GB RAM) and perform on par with native code. Deno leverages V8 fast api calls and JIT compiled bindings to achieve these high speeds.

Deno.dlopen generates an optimized and a fallback path. Optimized paths are triggered when V8 decides to optimize the function, hence call through the Fast API. Fallback paths handle types like function callbacks and implement proper error handling for unexpected types, that is not supported in Fast calls.

Optimized calls enter a JIT compiled function "trampoline" that translates Fast API values directly for symbol calls. JIT compilation itself is super fast, thanks to tinycc. Currently, the optimized path is only supported on Linux and MacOS.

To run benchmarks:

target/release/deno bench --allow-ffi --allow-read --unstable ./test_ffi/tests/bench.js