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

test: increase change_in_bytes for napi_adjust_external_memory test #57351

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

190n
Copy link

@190n 190n commented Mar 6, 2025

JavaScriptCore ignores small deltas in its interface for reporting external memory:

https://github.com/WebKit/WebKit/blob/8bbba2aa777cf326e24a4e5c63b1f51bd52315ff/Source/JavaScriptCore/heap/HeapInlines.h#L213-L229

More broadly, it seem reasonable for any other JS engine to do the same. Passing a large change ensures that the change is actually applied and the new adjusted value will be greater than zero (otherwise, the test relies on some external memory previously being reported as allocated). In turn, this makes the test more applicable to non-V8 implementations of Node-API.

JavaScriptCore ignores small deltas in its interface for reporting
external memory:

https://github.com/WebKit/WebKit/blob/8bbba2aa777cf326e24a4e5c63b1f51bd52315ff/Source/JavaScriptCore/heap/HeapInlines.h#L213-L229

More broadly, it seem reasonable for any other JS engine to do the same.
Passing a large change ensures that the change is actually applied and
the new adjusted value will be greater than zero (otherwise, the test
relies on some external memory previously being reported as allocated).
In turn, this makes the test more applicable to non-V8 implementations
of Node-API.
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests. labels Mar 6, 2025
@@ -215,7 +215,8 @@ static napi_value testAdjustExternalMemory(napi_env env, napi_callback_info info
napi_value result;
int64_t adjustedValue;

NODE_API_CALL(env, napi_adjust_external_memory(env, 1, &adjustedValue));
// Some JavaScript engines may ignore small increments passed to napi_adjust_external_memory
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific? What is the constraint you're seeing?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For JSC, right now the cutoff is set to 256 bytes: https://github.com/WebKit/WebKit/blob/8bbba2aa777cf326e24a4e5c63b1f51bd52315ff/Source/JavaScriptCore/heap/Heap.h#L645

I realize another possible solution is that implementations with imprecise external memory tracking could treat change_in_bytes as a floor on the return value -- basically, pretending that at least the currently requested change has had an effect. On Node's side this would basically be a docs change instead of a test change. At a glance from the PR #14310 where this was originally added, it seems like the question of what to do with an engine that cannot track external memory at all was brought up but not resolved, and it doesn't look like the possibility of memory tracking existing but with a minimum was brought up. The documentation only really describes this function's effect in V8.

I'd be happy with either approach.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the node-api adapter for WebKit should normalize small values if this is a WebKit constraint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. node-api Issues and PRs related to the Node-API. test Issues and PRs related to the tests.
Projects
Status: Need Triage
Development

Successfully merging this pull request may close these issues.

4 participants