ffi: allocate string argument storage lazily - #66178
Open
soulee-dev wants to merge 1 commit into
Open
soulee-dev wants to merge 1 commit into
soulee-dev wants to merge 1 commit into
Conversation
Collaborator
|
Review requested:
|
Reserve temporary string storage in InvokeFunction only when the first string argument is encountered. Calls without string arguments avoid allocating and freeing an unused vector buffer. Reserve capacity for all arguments before saving the first string pointer so subsequent strings cannot invalidate it. Add coverage for multiple strings, mixed Buffer arguments, and errors during argument conversion. Signed-off-by: Soul Lee <alus20x@gmail.com>
soulee-dev
force-pushed
the
ffi-lazy-string-storage
branch
from
September 21, 2026 11:57
c85110b to
aa0c8b5
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #66178 +/- ##
==========================================
- Coverage 90.29% 90.28% -0.01%
==========================================
Files 790 790
Lines 272021 272045 +24
Branches 51917 51936 +19
==========================================
+ Hits 245611 245612 +1
- Misses 16903 16941 +38
+ Partials 9507 9492 -15
🚀 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.
InvokeFunctionreserves a temporarystd::vector<std::string>on every call with arguments, even when none of the arguments are strings. Defer that reservation until the first string argument needs to be copied, avoiding an allocation and deallocation for calls without string arguments.The first string still reserves capacity for the full argument count before its pointer is saved. Subsequent strings therefore cannot reallocate the vector and invalidate pointers already prepared for the native call.
Add a test that exercises native argument conversion with multiple strings, empty and long strings, Unicode, mixed string/Buffer arguments, and errors while converting a later argument.
Local macOS ARM64 comparison using
benchmark/compare.js, with 10 samples per binary and the default iteration counts across all 40 FFI benchmark configurations:Both improvements remained significant at the 5% level after the runner's Holm-Bonferroni correction. The other 38 configurations showed no statistically significant difference in this run.
Validation:
--without-node-snapshot --without-node-code-cache).The full Node.js test suite and cross-platform CI have not been run.