-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fastpath for hasOwnProperty == true. #1449
Conversation
@curtisman @agarwal-sandeep please review? |
@dotnet-bot test Windows arm_test please |
BOOL expectedAnswer = object && object->HasOwnProperty(propertyId); | ||
#endif | ||
|
||
PropertyString *propString = requestContext->GetPropertyString(propertyId); |
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.
GetPropertyString [](start = 61, length = 17)
This goes and create a PropertyString if one is not present in that case type below won't match, should we have a different function which returns only if PropertyString is present. #Resolved
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'm not sure I'm understanding what's going on in this PR, but could this also add a fast path for |
@ljharb This code is the builtin for the function Object.hasOwnProperty, so we will always get this advantage no matter how that function is invoked. (I'll add a test case just to be sure.) I'll add some more information above about what this change accomplishes. |
awesome, thanks :-) |
PropertyString* ScriptContext::GetPropertyString(PropertyId propertyId) | ||
{ | ||
PropertyString *string = TryGetPropertyString(propertyId); | ||
if (string) |
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.
if (string) [](start = 8, length = 11)
if (string != nullptr)
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.
Thanks, done!
@dotnet-bot test Windows x64_test please |
Merge pull request #1449 from dilijev:hasown Adds a fastpath for the case when `Object.hasOwnProperty` returns `true` (meaning the property was found on the current object). This optimization was inspired by the observation that a very common pattern to use `Object.hasOwnProperty` in the following manner: ``` for (var x in obj) { if (obj.hasOwnProperty(x)) { // do something } } ``` From our observations, most instances of these patterns are used with shallow objects (objects with most of their enumerable properties on the object itself, rather than in the prototype chain), so most of the time, `Object.hasOwnProperty` would return true when invoked via the above pattern. Additionally, we have already created a property cache containing the type that a property was enumerated from, so we can use that information to trivially know whether the `this` parameter of `hasOwnProperty` was the same object on which we looked up that property, and if so, we know the answer is `true`.
Adds a fastpath for the case when
Object.hasOwnProperty
returnstrue
(meaning the property was found on the current object).This optimization was inspired by the observation that a very common pattern to use
Object.hasOwnProperty
in the following manner:From our observations, most instances of these patterns are used with shallow objects (objects with most of their enumerable properties on the object itself, rather than in the prototype chain), so most of the time,
Object.hasOwnProperty
would return true when invoked via the above pattern. Additionally, we have already created a property cache containing the type that a property was enumerated from, so we can use that information to trivially know whether thethis
parameter ofhasOwnProperty
was the same object on which we looked up that property, and if so, we know the answer istrue
.