You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi. As noted under the ref-napi issues list I've been wanting to update to use the ref-napi package but it's performance (and memory usage) was significantly slower (and larger) than the ref(NaN) version as others have observed. The ref-napi performance issues also impact ffi-napi.
The good news is I've identified the updates that need to be made to ffi-napi to make it properly work with a ref-napi with the 'performance updates' applied (including an additional update to ref-napi I identified as necessary, see my comments here 72 and here 76).
The updates necessary to ffi-napi are to code that expects that a pointer is a '0-length buffer'. I haven't found anything in the documentation that actually indicates that this is or should be true, and from what I can tell a pointer should be a '1-length buffer' (to hold the pointer itself). With the changes to ref-napi for performance and memory usage a pointer explicitly becomes a '1-length Buffer' which I believe is it's correct behavior (I do have to admit to being confused as to how the previous behavior actually worked in so much as storing a pointer in a Buffer that became 'zero length' on return from the C/C++ code).
Long story short, ffi-napi calls 'WrapPointer' of the ref-napi package (at the C/C++ code level) without specifying a size, since ref-napi now makes a pointer Buffer a 1-length Buffer the existing ffi-napi package won't work. The fix is to add a size of '1' to these WrapPointer calls, here's an example:
original line:
o["dlopen"] = WrapPointer(env, dlopen);
Updated line
o["dlopen"] = WrapPointer(env, dlopen,1);
I'm attaching a diff of the changes to be made to src/callback_info.cc, src/ffi.cc, test/ffi_test.cc, test/dynamic_library.js (to account for a test that assumed a pointer was a 0 length buffer).
With the updates to ref-napi & these updates the ffi-napi package passes all it's mocha tests.
Equally importantly (to me anyway) is that I've tested these changes to my own project & they work great. This was a limited but full test of my code that makes extensive use of ffi-napi, ref-napi & ref-struct-di, the performance was easily on par with the equivalent NaN packages, potentially slightly better.
I hope that someone will apply these patches (or equivalent ones in case I've entirely misunderstood how the ref-napi package should create a pointer Buffer) to the official ref-napi & ffi-napi packages so that others can test them.
Thanks.
PS. My apologies if this isn't correct usage of this forum. If there was a better way to submit this please advise.
Hi. As noted under the ref-napi issues list I've been wanting to update to use the ref-napi package but it's performance (and memory usage) was significantly slower (and larger) than the ref(NaN) version as others have observed. The ref-napi performance issues also impact ffi-napi.
The good news is I've identified the updates that need to be made to ffi-napi to make it properly work with a ref-napi with the 'performance updates' applied (including an additional update to ref-napi I identified as necessary, see my comments here 72 and here 76).
The updates necessary to ffi-napi are to code that expects that a pointer is a '0-length buffer'. I haven't found anything in the documentation that actually indicates that this is or should be true, and from what I can tell a pointer should be a '1-length buffer' (to hold the pointer itself). With the changes to ref-napi for performance and memory usage a pointer explicitly becomes a '1-length Buffer' which I believe is it's correct behavior (I do have to admit to being confused as to how the previous behavior actually worked in so much as storing a pointer in a Buffer that became 'zero length' on return from the C/C++ code).
Long story short, ffi-napi calls 'WrapPointer' of the ref-napi package (at the C/C++ code level) without specifying a size, since ref-napi now makes a pointer Buffer a 1-length Buffer the existing ffi-napi package won't work. The fix is to add a size of '1' to these WrapPointer calls, here's an example:
original line:
o["dlopen"] = WrapPointer(env, dlopen);
Updated line
o["dlopen"] = WrapPointer(env, dlopen,1);
I'm attaching a diff of the changes to be made to src/callback_info.cc, src/ffi.cc, test/ffi_test.cc, test/dynamic_library.js (to account for a test that assumed a pointer was a 0 length buffer).
With the updates to ref-napi & these updates the ffi-napi package passes all it's mocha tests.
Equally importantly (to me anyway) is that I've tested these changes to my own project & they work great. This was a limited but full test of my code that makes extensive use of ffi-napi, ref-napi & ref-struct-di, the performance was easily on par with the equivalent NaN packages, potentially slightly better.
I hope that someone will apply these patches (or equivalent ones in case I've entirely misunderstood how the ref-napi package should create a pointer Buffer) to the official ref-napi & ffi-napi packages so that others can test them.
Thanks.
PS. My apologies if this isn't correct usage of this forum. If there was a better way to submit this please advise.
node-ffi-napi-diff.txt
The text was updated successfully, but these errors were encountered: