ffi: add shared-buffer fast path for numeric and pointer signatures#62918
Open
bengl wants to merge 2 commits intonodejs:mainfrom
Open
ffi: add shared-buffer fast path for numeric and pointer signatures#62918bengl wants to merge 2 commits intonodejs:mainfrom
bengl wants to merge 2 commits intonodejs:mainfrom
Conversation
Collaborator
|
Review requested:
|
Adds microbenchmarks covering the common FFI call shapes so future changes to the invoker can be evaluated: - add-i32.js: 2-arg integer - add-f64.js: 2-arg float - many-args.js: 6-arg integer - pointer-bigint.js: 1-arg pointer (BigInt) - sum-buffer.js: pointer + length (Buffer) A `common.js` helper resolves the fixture-library path from `test/ffi/fixture_library` without pulling in the test harness, and throws a clear message if the fixture hasn't been built yet. Also adds `sum_6_i32` to the fixture library for the many-args case.
5dea1bf to
7b165f9
Compare
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.
7b165f9 to
676f0ae
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #62918 +/- ##
==========================================
- Coverage 89.61% 89.50% -0.11%
==========================================
Files 706 707 +1
Lines 219218 219871 +653
Branches 42002 42070 +68
==========================================
+ Hits 196446 196794 +348
- Misses 14666 14936 +270
- Partials 8106 8141 +35
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withoutgoing through V8's
FunctionCallbackInfo. Results are returned the sameway.
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
InvokeFunctionpath via astashed
_invokeSlowfunction. Signatures containingnon-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, andlibrary.functionsnow have
.lengthequal to the declared parameter count rather than0. Code that relied on the previous value will need to be updated.This is largely based on #46905, which is largely based on https://github.com/bengl/sbffi.
Benchmark output: