-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
n-api: adds function to adjust external memory #14310
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments, otherwise LGTM – thanks!
doc/api/n-api.md
Outdated
@@ -3155,6 +3155,21 @@ support it: | |||
* If the function is not available, provide an alternate implementation | |||
that does not use the function. | |||
|
|||
### napi_adjust_external_memory | |||
<!-- YAML | |||
added: v8.0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use added: REPLACEME
here?
@@ -58,3 +58,6 @@ test_general.wrap(x, 25); | |||
assert.throws(function() { | |||
test_general.wrap(x, 'Blah'); | |||
}, Error); | |||
|
|||
// test napi_adjust_external_memory | |||
assert.ok(typeof test_general.testAdjustExternalMemory() === 'number'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you use assert.strictEqual
for this kind of check?
doc/api/n-api.md
Outdated
--> | ||
```C | ||
NAPI_EXTERN int64_t napi_adjust_external_memory(napi_env env, | ||
int64_t change_in_bytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't run the C++ linter against Markdown files yet.
doc/api/n-api.md
Outdated
@@ -3170,6 +3185,7 @@ support it: | |||
[Working with JavaScript Values]: #n_api_working_with_javascript_values | |||
[Working with JavaScript Values - Abstract Operations]: #n_api_working_with_javascript_values_abstract_operations | |||
|
|||
[`napi_adjust_external_memory`]: #n_api_napi_adjust_external_memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need this unless there is a reference to it.
src/node_api.h
Outdated
@@ -512,6 +512,10 @@ NAPI_EXTERN napi_status napi_cancel_async_work(napi_env env, | |||
// version management | |||
NAPI_EXTERN napi_status napi_get_version(napi_env env, uint32_t* result); | |||
|
|||
// Garbage collection |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the comment. Does adjusting the external memory trigger a gc ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It controls the operations of the GC, so I think the heading is appropriate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM besides the doc nit.
doc/api/n-api.md
Outdated
@@ -3155,6 +3155,21 @@ support it: | |||
* If the function is not available, provide an alternate implementation | |||
that does not use the function. | |||
|
|||
### napi_adjust_external_memory |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -512,6 +512,10 @@ NAPI_EXTERN napi_status napi_cancel_async_work(napi_env env, | |||
// version management | |||
NAPI_EXTERN napi_status napi_get_version(napi_env env, uint32_t* result); | |||
|
|||
// Garbage collection | |||
NAPI_EXTERN int64_t napi_adjust_external_memory(napi_env env, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
kept alive by JavaScript objects. | ||
- `[out] result`: The adjusted value | ||
|
||
Returns `napi_ok` if the API succeeded. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like this is missing a description of what the method actually does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a description below
@@ -58,3 +58,6 @@ test_general.wrap(x, 25); | |||
assert.throws(function() { | |||
test_general.wrap(x, 'Blah'); | |||
}, Error); | |||
|
|||
// test napi_adjust_external_memory | |||
assert.notStrictEqual(test_general.testAdjustExternalMemory(), -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add some tests for invalid values.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yea
@chris--young you still working on this ? |
@mhdawson yea ill wrap it up this weekend |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -58,3 +58,6 @@ test_general.wrap(x, 25); | |||
assert.throws(function() { | |||
test_general.wrap(x, 'Blah'); | |||
}, Error); | |||
|
|||
// test napi_adjust_external_memory | |||
assert.strictEqual(typeof test_general.testAdjustExternalMemory(), 'number'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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::AdjustAmountOfExternalAllocatedMemory
One 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