1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-28 16:20:57 -05:00
denoland-deno/ext/ffi
Divy Srivastava 53606de634
BREAKING(ffi/unstable): always return u64 as bigint (#23981)
The mixed `number | bigint` representation was useful optimization for
pointers. Now, pointers are represented as V8 externals. As part of the
FFI stabilization effort we want to make `bigint` the only
representation for `u64` and `i64`.

BigInt representation performance is almost on par with mixed
representation with the added benefit that its less confusing and users
don't need manual checks and conversions for doing operations on the
value.

```
cpu: AMD Ryzen 5 7530U with Radeon Graphics
runtime: deno 1.43.6+92a8d09 (x86_64-unknown-linux-gnu)

file:///home/divy/gh/ffi/main.ts
benchmark                 time (avg)        iter/s             (min … max)       p75       p99      p995
-------------------------------------------------------------------------- -----------------------------
nop                        4.01 ns/iter 249,533,690.5     (3.97 ns … 10.8 ns) 3.97 ns 4.36 ns 9.03 ns
ret bigint                 7.74 ns/iter 129,127,186.8    (7.72 ns … 10.46 ns) 7.72 ns 8.11 ns 8.82 ns
ret i32                    7.81 ns/iter 128,087,100.5    (7.77 ns … 12.72 ns) 7.78 ns 8.57 ns 9.75 ns
ret bigint (add op)       15.02 ns/iter  66,588,253.2   (14.64 ns … 24.99 ns) 14.76 ns 19.13 ns 19.44 ns
ret i32    (add op)       12.02 ns/iter  83,209,131.8   (11.95 ns … 18.18 ns) 11.98 ns 13.11 ns 14.5 ns
```
2024-05-28 09:31:09 +05:30
..
00_ffi.js BREAKING(ffi/unstable): always return u64 as bigint (#23981) 2024-05-28 09:31:09 +05:30
call.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
callback.rs BREAKING(ffi/unstable): always return u64 as bigint (#23981) 2024-05-28 09:31:09 +05:30
Cargo.toml chore: forward v1.43.6 release commit to main (#23936) 2024-05-22 01:35:04 +00:00
dlfcn.rs chore: update to Rust 1.77.2 (#23262) 2024-04-10 22:08:23 +00:00
ir.rs BREAKING(ffi/unstable): always return u64 as bigint (#23981) 2024-05-28 09:31:09 +05:30
lib.rs BREAKING(ffi/unstable): always return u64 as bigint (#23981) 2024-05-28 09:31:09 +05:30
README.md chore: move test_ffi and test_nap to tests/ [WIP] (#22394) 2024-02-12 13:46:50 -07:00
repr.rs chore: upgrade deno_core to 0.244.0 (#21859) 2024-01-09 17:25:10 +01:00
static.rs BREAKING(ffi/unstable): always return u64 as bigint (#23981) 2024-05-28 09:31:09 +05:30
symbol.rs chore: update copyright to 2024 (#21753) 2024-01-01 19:58:21 +00:00
turbocall.rs chore(ext/ffi): sym is unused on aarch64 linux (#23188) 2024-04-02 20:57:31 +00:00

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-ffi ./tests/ffi/tests/bench.js