-
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
Enable ES6IsConcatSpreadable under experimental #1198
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -964,6 +964,72 @@ namespace Js | |
void Unregister(ScriptContext * scriptContext); | ||
}; | ||
|
||
// Two-entry Type-indexed circular cache | ||
// cache IsConcatSpreadable() result unless user-defined [@@isConcatSpreadable] exists | ||
class IsConcatSpreadableCache | ||
{ | ||
Type *type0, *type1; | ||
int lastAccess; | ||
BOOL result0, result1; | ||
|
||
public: | ||
IsConcatSpreadableCache() : | ||
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. Initialized these as initialization list. |
||
type0(nullptr), | ||
type1(nullptr), | ||
result0(FALSE), | ||
result1(FALSE), | ||
lastAccess(1) | ||
{ | ||
} | ||
|
||
bool TryGetIsConcatSpreadable(Type *type, _Out_ BOOL *result) | ||
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. nit: changed to bool |
||
{ | ||
Assert(type != nullptr); | ||
Assert(result != nullptr); | ||
|
||
*result = FALSE; | ||
if (type0 == type) | ||
{ | ||
*result = result0; | ||
lastAccess = 0; | ||
return true; | ||
} | ||
|
||
if (type1 == type) | ||
{ | ||
*result = result1; | ||
lastAccess = 1; | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
void CacheIsConcatSpreadable(Type *type, BOOL result) | ||
{ | ||
Assert(type != nullptr); | ||
|
||
if (lastAccess == 0) | ||
{ | ||
type1 = type; | ||
result1 = result; | ||
lastAccess = 1; | ||
} | ||
else | ||
{ | ||
type0 = type; | ||
result0 = result; | ||
lastAccess = 0; | ||
} | ||
} | ||
|
||
void Invalidate() | ||
{ | ||
type0 = nullptr; | ||
type1 = nullptr; | ||
} | ||
}; | ||
|
||
#if defined(_M_IX86_OR_ARM32) | ||
CompileAssert(sizeof(IsInstInlineCache) == 0x10); | ||
#else | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1357,17 +1357,45 @@ namespace Js | |
|
||
RecyclableObject* instance = RecyclableObject::FromVar(instanceVar); | ||
ScriptContext* scriptContext = instance->GetScriptContext(); | ||
|
||
if (!PHASE_OFF1(IsConcatSpreadableCachePhase)) | ||
{ | ||
BOOL retVal = FALSE; | ||
Type *instanceType = instance->GetType(); | ||
IsConcatSpreadableCache *isConcatSpreadableCache = scriptContext->GetThreadContext()->GetIsConcatSpreadableCache(); | ||
|
||
if (isConcatSpreadableCache->TryGetIsConcatSpreadable(instanceType, &retVal)) | ||
{ | ||
OUTPUT_TRACE(Phase::IsConcatSpreadableCachePhase, _u("IsConcatSpreadableCache hit: %p\n"), instanceType); | ||
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. nit: changed to use OUTPUT_TRACE |
||
return retVal; | ||
} | ||
|
||
Var spreadable = nullptr; | ||
BOOL hasUserDefinedSpreadable = JavascriptOperators::GetProperty(instance, instance, PropertyIds::_symbolIsConcatSpreadable, &spreadable, scriptContext); | ||
|
||
if (hasUserDefinedSpreadable && spreadable != scriptContext->GetLibrary()->GetUndefined()) | ||
{ | ||
return JavascriptConversion::ToBoolean(spreadable, scriptContext); | ||
} | ||
|
||
retVal = JavascriptOperators::IsArray(instance); | ||
|
||
if (!hasUserDefinedSpreadable) | ||
{ | ||
OUTPUT_TRACE(Phase::IsConcatSpreadableCachePhase, _u("IsConcatSpreadableCache saved: %p\n"), instanceType); | ||
isConcatSpreadableCache->CacheIsConcatSpreadable(instanceType, retVal); | ||
} | ||
|
||
return retVal; | ||
} | ||
|
||
Var spreadable = JavascriptOperators::GetProperty(instance, PropertyIds::_symbolIsConcatSpreadable, scriptContext); | ||
if (spreadable != scriptContext->GetLibrary()->GetUndefined()) | ||
{ | ||
return JavascriptConversion::ToBoolean(spreadable, scriptContext); | ||
} | ||
if (JavascriptOperators::IsArray(instance)) | ||
{ | ||
return true; | ||
} | ||
return false; | ||
|
||
return JavascriptOperators::IsArray(instance); | ||
} | ||
|
||
Var JavascriptOperators::OP_LdCustomSpreadIteratorList(Var aRight, ScriptContext* scriptContext) | ||
|
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.
Did you do any experimentation with different cache sizes?
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.
Yes. Tried 1-, 2-, and 3-entry caches. From 1 to 2 saw significant perf gain; from 2 to 3 no gain. Therefore chose 2-entry for simplicity.
In reply to: 68804491 [](ancestors = 68804491)
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.
Cool, good to know.