n-api: adds function to adjust external memory#14310
n-api: adds function to adjust external memory#14310chris--young wants to merge 4 commits intonodejs:masterfrom
Conversation
addaleax
left a comment
There was a problem hiding this comment.
Two comments, otherwise LGTM – thanks!
doc/api/n-api.md
Outdated
There was a problem hiding this comment.
Can you use added: REPLACEME here?
There was a problem hiding this comment.
Can you use assert.strictEqual for this kind of check?
doc/api/n-api.md
Outdated
There was a problem hiding this comment.
I think the parameters should be aligned here, that probably means the first one will have to be on a new line. I'm surprised the linter did not complain about this.
There was a problem hiding this comment.
We don't run the C++ linter against Markdown files yet.
doc/api/n-api.md
Outdated
There was a problem hiding this comment.
I don't think we need this unless there is a reference to it.
src/node_api.h
Outdated
There was a problem hiding this comment.
Not sure about the comment. Does adjusting the external memory trigger a gc ?
There was a problem hiding this comment.
No, I don't think it triggers a gc but it is related to gc and I wanted to avoid any confusion with the "version management" comment above. I can remove this line if you think that would be best.
There was a problem hiding this comment.
It controls the operations of the GC, so I think the heading is appropriate.
There was a problem hiding this comment.
Needs more detail though. Many people will wonder the same thing as @mhdawson when it's just one of many input signals that influence the frequency of GC runs.
|
Thanks for picking this up. In terms of the Chakra implementation I think we (the N-API team) agreed to let the Microsoft team figure out how to implement new functions like this. Left a few comments. |
doc/api/n-api.md
Outdated
There was a problem hiding this comment.
I think you would need a "Garbage Collection" heading here as well, so as to not categorize it under "Version Management".
src/node_api.h
Outdated
There was a problem hiding this comment.
I think napi_status napi_adjust_external_memory(napi_env env, int64_t change_in_bytes, int64_t* result) would be more consistent with the rest of the API, since almost everything else returns a napi_status.
doc/api/n-api.md
Outdated
There was a problem hiding this comment.
Seems like this is missing a description of what the method actually does.
There was a problem hiding this comment.
Can you add some tests for invalid values.
|
@chris--young you still working on this ? |
|
@mhdawson yea ill wrap it up this weekend |
digitalinfinity
left a comment
There was a problem hiding this comment.
LGTM (although agree with @cjihrig that we should document it more precisely). For the node-chakracore side of the house, we welcome PRs 😄 - if you ping me on the ChakraCore gitter channel, happy to help guide you to make that change.
|
@chris--young thanks for your help on this :) |
|
@cjihrig please review again I looked into testing for invalid values, but it seems like there isn't much to be done there. V8 handles the change gracefully even if you exceed the external allocation limit or pass in 0. Any other bad values should be prevented by the compiler. |
|
@digitalinfinity i'd definitely like to help out on the node-chakracore side too. I'll follow up with you after my changes here have been fully approved. |
There was a problem hiding this comment.
can we also test that the number is >0. I believe that we probably can't tell what the number will be, but I think we can depend on it being >0 ?
Added a simple wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory Fixes: nodejs#13928
Improved documentation based on pull request feedback Fixes: nodejs#13928
Changed napi_adjust_external_memory() signature to be more consistent with the rest of the API Fixes: nodejs#13928
Improved unit tests Fixes: nodejs#13928
|
I guess this is ready to land? |
|
Landed in c77e6d3 |
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: #14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: #13928
|
@benjamingr that was timing 😆 |
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: nodejs#14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: nodejs#13928
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: nodejs/node#14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: nodejs/node#13928
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: #14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: #13928
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: #14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: #13928
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: nodejs#14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: nodejs#13928
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory Backport-PR-URL: #19447 PR-URL: #14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: #13928
Added a simple wrapper around
v8::Isolate::AdjustAmountOfExternalAllocatedMemoryOne of the requests from @mhdawson's original issue was for this to act as a no-op on unsupported vms. I am a little unsure of the best way to handle that. As far as I can tell Chakra is the only unsupported vm we need to do account for and figure the easiest thing to do would be for me to open a second pr against node-charkracore where
napi_adjust_external_memory()always returns-1(or something along those lines). But I'm worried that will cause a conflict when merging the two repos.Fixes: #13928
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
n-api