Repository navigation
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.
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.
|
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.
if (string) [](start = 8, length = 11)
if (string != nullptr)
|
|
|
@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.hasOwnPropertyreturnstrue(meaning the property was found on the current object).This optimization was inspired by the observation that a very common pattern to use
Object.hasOwnPropertyin 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.hasOwnPropertywould 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 thethisparameter ofhasOwnPropertywas the same object on which we looked up that property, and if so, we know the answer istrue.