ffi: reuse libffi call plans - #64958
Open
umuoy1 wants to merge 2 commits into
Open
Conversation
Precompute a libffi call plan for each fixed signature on x86-64 System V and reuse it from the generic and SharedBuffer invokers. This avoids repeating argument-placement work for every call. Continue to use ffi_call() with libffi older than 3.7, on other ABIs, and when plan allocation fails. Signed-off-by: umuoy1 <burningdian@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #64958 +/- ##
==========================================
- Coverage 90.28% 90.28% -0.01%
==========================================
Files 760 762 +2
Lines 247076 247536 +460
Branches 46594 46680 +86
==========================================
+ Hits 223081 223484 +403
- Misses 15458 15495 +37
- Partials 8537 8557 +20
🚀 New features to boost your workflow:
|
Measure the call path for signatures that bypass the V8 Fast API and reach FFIFunction::Invoke(), covering a register-only and a stack-spilled libffi call plan on x86-64 System V. The per-call delta is the decision-relevant metric for reusable call plans: plan allocation is a one-time cost that amortizes within a few calls. Signed-off-by: umuoy1 <burningdian@gmail.com>
umuoy1
force-pushed
the
ffi-reuse-call-plans
branch
from
August 3, 2026 09:51
6d678be to
249d729
Compare
mcollina
requested review from
ShogunPanda and
trivikr
and removed request for
ShogunPanda
August 3, 2026 10:31
Collaborator
gurgunday
approved these changes
Aug 3, 2026
ShogunPanda
approved these changes
Aug 3, 2026
trivikr
approved these changes
Aug 3, 2026
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.
Fixes: #64562
Refs: libffi/libffi@3cc6beb
libffi 3.7 introduced reusable call plans that precompute argument placement. Node.js FFI functions have fixed signatures, so this change creates a plan during function preparation and reuses it for generic and SharedBuffer calls on x86-64 System V.
Other platforms, older libffi versions, and allocation failures continue to use
ffi_call(). An invocation benchmark is included: it measures the call path for signatures that bypass the V8 Fast API and reach FFIFunction::Invoke(), covering a register-only and a stack-spilled call plan.Before (
ffi_call):call_int_callback— (function, i32) → i32sum_8_i32— (i32 × 8) → i32After (
ffi_call_plan_invoke, plan reused):call_int_callback— (function, i32) → i32sum_8_i32— (i32 × 8) → i32