Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.2k
node-api: refactor napi_set_property function for improved performance #50282
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
Uh oh!
There was an error while loading. Please reload this page.
Conversation
mertcanaltin commented Oct 19, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
nodejs-github-bot commented Oct 19, 2023
Review requested:
|
1047cc3 to f686b2eComparevmoroz commented Oct 27, 2023
@mertcanaltin , thank you for working on the improvements to Node-API! It seems that the change is targeting to address the same issues as we discussed them in #45905. A better approach would be to create property keys with Would you be interested to implement such functions that create internalized strings? napi_status node_api_create_property_key_latin1(napi_env env, constchar* str, size_t length, napi_value* result); napi_status node_api_create_property_key_utf8(napi_env env, constchar* str, size_t length, napi_value* result); napi_status node_api_create_property_key_utf16(napi_env env, constchar16_t* str, size_t length, napi_value* result); napi_status node_api_create_property_key(napi_env env, napi_value str_or_sym, napi_value* result);The first three functions must create internalized strings from latin1, utf8, and utf16 strings. The last one must internalize |
mertcanaltin commented Nov 3, 2023
Thank you very much for reviewing and detailing, I will be working on it again with an update in the future |
mertcanaltin commented Nov 6, 2023
This commit refactors the napi_set_property_utf16 function to use internalized string property keys, which can lead to better performance. It implements @vmoroz suggestion to create internalized string property keys for accessing object properties. Internalized keys improve speed for property access operations like set, get, has, and delete by allowing V8 to compare string pointers instead of the entire string. This change aligns with the proposal in issue #45905. New functions added:
This change is expected to enhance the overall performance of Node-API operations involving property access. Fixes: #50282 |
vmoroz commented Nov 6, 2023
@mertcanaltin , thank you for starting to implement the property key creation functions! I believe the Please have a look at the PR #48339 where we added creating external strings. |
mertcanaltin commented Nov 6, 2023
greetings thank you very much for your suggestions, I applied it, now I think I need to add a test and update the document @vmoroz |
vmoroz commented Nov 6, 2023
Awesome! Could you use the napi_status NAPI_CDECL node_api_create_property_key_utf16(napi_env env, constchar16_t* str, size_t length, napi_value* result){returnv8impl::NewString(env, str, length, result, [&](v8::Isolate* isolate){returnv8::String::NewFromTwoByte(isolate, reinterpret_cast<constuint16_t*>(str), v8::NewStringType::kInternalized, static_cast<int>(length))})} |
mertcanaltin commented Nov 7, 2023
thank you for your suggestion I updated as you said @vmoroz |
vmoroz commented Nov 10, 2023
@mertcanaltin , perfect! |
mertcanaltin commented Nov 12, 2023
I made the additions as you said @vmoroz 🚀 🕺 |
mertcanaltin commented Nov 12, 2023
I think I have a problem with the napiVersion |
vmoroz commented Nov 12, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
@mertcanaltin. it looks great!
Also, please put the code for the new string APIs next to the string creation APIs added in PR #48339. |
mertcanaltin commented Nov 13, 2023
these steps were great I hope I succeeded I made an update @vmoroz 🚀 |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
nodejs-github-bot commented Dec 20, 2023
| returnv8::String::NewFromTwoByte(isolate, | ||
| reinterpret_cast<constuint16_t*>(str), | ||
| v8::NewStringType::kInternalized, | ||
| static_cast<int>(length)); |
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.
Why do we need to cast to int here? We don't cast to int in the regular version of this function.
mertcanaltinDec 22, 2023 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
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.
@gabrielschulhof , we are getting warnings in MSVC compiler if types are mismatch.
The NewFromTwoByte expects type int which is signed 32-bit integer.
In this function length is size_t which is unsigned 64-bit integer for 64 platforms.
MSVC warns about possible precision loss when the cast implicitly here.
The explicit cast suppresses the warning as we explicitly express our intent.
Ideally, we must add the cast in other places too to avoid the MSVC warnings.
But it should be another PR since currently Node.js has a lot of MSVC warnings anyway.
Uh oh!
There was an error while loading. Please reload this page.
lint added empty line
mertcanaltin commented Dec 22, 2023
I removed my tag so as not to do something wrong, maybe the whole pipeline should go through and then I thought I should do it. 🤔 |
nodejs-github-bot commented Dec 23, 2023
mertcanaltin commented Dec 30, 2023
I wonder if I should do an update here @vmoroz 🚀 |
vmoroz commented Dec 31, 2023
@mertcanaltin , it seems that CI has some flaky tests. I see other PRs have the same issue. |
nodejs-github-bot commented Dec 31, 2023
nodejs-github-bot commented Jan 2, 2024
nodejs-github-bot commented Jan 5, 2024
PR-URL: #50282 Reviewed-By: Vladimir Morozov <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
mhdawson commented Jan 5, 2024
Landed in 59e7444 @mertcanaltin thanks for your work and patience on this one. |
mertcanaltin commented Jan 5, 2024
thank you very much for your support ❤️ |
PR-URL: nodejs#50282 Reviewed-By: Vladimir Morozov <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
PR-URL: nodejs#50282 Reviewed-By: Vladimir Morozov <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
PR-URL: #50282 Reviewed-By: Vladimir Morozov <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
PR-URL: #50282 Reviewed-By: Vladimir Morozov <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
PR-URL: #50282 Reviewed-By: Vladimir Morozov <[email protected]> Reviewed-By: Michael Dawson <[email protected]> Reviewed-By: Chengzhong Wu <[email protected]>
Node.js PR #50282 - N-API Performance Improvement
This pull request aims to optimize the
napi_set_propertyfunction to enhance the overall performance of Node-API. The changes include:node_api_create_property_key_utf16function has been updated to match the proposed format.node_api_create_property_key_utf16function is now implemented using theNewStringfunction for a more streamlined approach.napi_set_property_utf16function, which did not provide additional advantages overnode_api_create_property_key_utf16, has been removed.It's worth noting that these changes are focused on improving the overall performance of Node-API operations, especially those involving property access.
/w @vmoroz 🙏
issue: #49922