Skip to content

Commit 7b165f9

Browse files
committed
ffi: add shared-buffer fast path for numeric and pointer signatures
Adds an ArrayBuffer-based invocation path for FFI functions whose signatures are composed entirely of numeric types (i8..i64, u8..u64, f32, f64, bool, char) and/or pointer types. The JS wrapper packs arguments directly into a per-function AB via primordial DataView setters and the C++ invoker (`InvokeFunctionSB`) reads them without going through V8's `FunctionCallbackInfo`. Results are returned the same way. Pointer arguments use runtime dispatch: BigInt, null, and undefined take the fast path, while Buffer, ArrayBuffer, ArrayBufferView, and String fall back transparently to the classic `InvokeFunction` path via a stashed `_invokeSlow` function. Signatures containing non-numeric/non-pointer types also bypass the fast path. The fast path is disabled on big-endian platforms. Callers do not opt in, and the fast path is transparent in every way users should rely on. One observable change: function wrappers returned by `library.getFunction`, `library.getFunctions`, and `library.functions` now have `.length` equal to the declared parameter count rather than `0`. Code that relied on the previous value will need to be updated.
1 parent 5b88d45 commit 7b165f9

10 files changed

Lines changed: 1706 additions & 31 deletions

File tree

lib/ffi.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ const {
5353
toArrayBuffer,
5454
} = internalBinding('ffi');
5555

56+
require('internal/ffi-shared-buffer');
57+
5658
function checkFFIPermission() {
5759
if (!permission.isEnabled() || permission.has('ffi')) {
5860
return;

0 commit comments

Comments
 (0)