-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
util,assert: improve comparison performance #22197
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
This significantly improves regular and typed array performance by not checking the indices keys anymore. This can be done with a V8 API that allows to only retrieve the non indices property keys.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,22 @@ using v8::Proxy; | |
| using v8::String; | ||
| using v8::Value; | ||
|
|
||
| static void GetOwnNonIndicesProperties( | ||
| const FunctionCallbackInfo<Value>& args) { | ||
| Environment* env = Environment::GetCurrent(args); | ||
| Local<Context> context = env->context(); | ||
|
|
||
| v8::Local<v8::Object> object = args[0].As<v8::Object>(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I couldn't see if we have a check for this in-place. Will we crash if this fails? That said, does it ever really realistically fail?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it would crash. But this API is only used internally and not exposed. That's why I did not add a safeguard against wrong input values.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a check for that as well. |
||
|
|
||
| // Return only non-enumerable properties by default. | ||
| v8::Local<v8::Array> properties = object | ||
| ->GetPropertyNames(context, v8::KeyCollectionMode::kOwnOnly, | ||
| v8::ONLY_ENUMERABLE, | ||
| v8::IndexFilter::kSkipIndices) | ||
| .ToLocalChecked(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above, does this ever fail? Instead, you could try something like
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not aware about this. I use it as it's done in the V8 tests. @nodejs/v8 do we have to add a guard against this?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you do, yes. The whole point of
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the original behavior of
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Exactly. Returning (throwing) if the if (!call(...)->ToLocal(&result) {
DCHECK(isolate->has_pending_exception());
return;
}
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, please use @ryzokuken’s suggestion here, I think this could otherwise fail when inspecting Proxies with an
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks a lot! I learned something through your comments 👍. It is now handled as suggested. |
||
| args.GetReturnValue().Set(properties); | ||
| } | ||
|
|
||
| static void GetPromiseDetails(const FunctionCallbackInfo<Value>& args) { | ||
| // Return undefined if it's not a Promise. | ||
| if (!args[0]->IsPromise()) | ||
|
|
@@ -177,6 +193,8 @@ void Initialize(Local<Object> target, | |
| env->SetMethodNoSideEffect(target, "getProxyDetails", GetProxyDetails); | ||
| env->SetMethodNoSideEffect(target, "safeToString", SafeToString); | ||
| env->SetMethodNoSideEffect(target, "previewEntries", PreviewEntries); | ||
| env->SetMethodNoSideEffect(target, "getOwnNonIndicesProperties", | ||
| GetOwnNonIndicesProperties); | ||
|
|
||
| env->SetMethod(target, "startSigintWatchdog", StartSigintWatchdog); | ||
| env->SetMethod(target, "stopSigintWatchdog", StopSigintWatchdog); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.