node-ffi-napi / ref-napi

Turn Buffer instances into "pointers"
MIT License
123 stars 67 forks source link

Change to using std::min() when allocating Buffers #73

Open doggkruse opened 2 years ago

doggkruse commented 2 years ago

This will result in Buffers being allocated to the size requested up to kMaxLength (0x3fffffff) instead of the current behavior of always allocating kMaxLength. Since these buffers are allocated in the node external memory (limited to 64M) the old behavior would very quickly cause massive GC pressure as the GC is triggered on each new Buffer allocation once the node external memory limit is reached. It appears the old behavior was not intentional and should have always been std::min(). This should fix #72

genaris commented 1 year ago

@addaleax by chance is it possible this to be reviewed and/or merged? It's solving our performance issues in Node.Js 18. However, as @blattersturm mentioned in #72, in Node 14 and 16 does not work because it's throwing Check failed: result.second. Maybe something that has been fixed in recent v8 engine but not back-ported? If you have any hint or guidance about to make it work in all Node versions I'd really appreciate. Thanks!