Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from

Conversation

doggkruse
Copy link

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

…his 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 node-ffi-napi#72
…an the current request. This is likely what drove the problematic max size allocation
@genaris
Copy link

genaris commented Jan 19, 2023

@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!

genaris added a commit to 2060-io/ref-napi that referenced this pull request Feb 6, 2023
NOTE: ref-napi now requires node >= 18, as this is not working in previous versions

Signed-off-by: Ariel Gentile <gentilester@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

std::max(..., kMaxLength leads to massive GC pressure
2 participants