Skip to content

Commit

Permalink
Optimize JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeHolman committed Oct 26, 2017
1 parent 6df14a2 commit f10138e
Show file tree
Hide file tree
Showing 31 changed files with 1,618 additions and 1,083 deletions.
11 changes: 0 additions & 11 deletions lib/Backend/JITTimeFunctionBody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,17 +957,6 @@ JITTimeFunctionBody::GetConstTable() const
return m_bodyData.constTable;
}

bool
JITTimeFunctionBody::IsConstRegPropertyString(Js::RegSlot reg, ScriptContextInfo * context) const
{
RecyclableObjectIDL * content = m_bodyData.constTableContent->content[reg - Js::FunctionBody::FirstRegSlot];
if (content != nullptr && content->vtbl == context->GetVTableAddress(VtablePropertyString))
{
return true;
}
return false;
}

intptr_t
JITTimeFunctionBody::GetRootObject() const
{
Expand Down
1 change: 0 additions & 1 deletion lib/Backend/JITTimeFunctionBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ class JITTimeFunctionBody
intptr_t GetIsInstInlineCache(uint index) const;
Js::TypeId GetConstantType(Js::RegSlot location) const;
void * GetConstTable() const;
bool IsConstRegPropertyString(Js::RegSlot reg, ScriptContextInfo * context) const;

intptr_t GetRootObject() const;
intptr_t GetLoopHeaderAddr(uint loopNum) const;
Expand Down
2 changes: 1 addition & 1 deletion lib/Backend/JnHelperMethodList.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ HELPERCALL(ScrObj_LdStrictInnerFrameDisplayNoParent, Js::JavascriptOperators::OP
HELPERCALL(ScrObj_OP_IsInst, Js::JavascriptOperators::OP_IsInst, AttrCanThrow)

HELPERCALL(Op_IsIn, Js::JavascriptOperators::IsIn, AttrCanThrow)
HELPERCALL(Op_IsObject, Js::JavascriptOperators::IsObject, AttrCanThrow)
HELPERCALL(Op_IsObject, (BOOL (*) (Js::Var))Js::JavascriptOperators::IsObject, AttrCanThrow)
HELPERCALL(Op_IsClassConstructor, Js::JavascriptOperators::IsClassConstructor, AttrCanThrow)
HELPERCALL(Op_IsBaseConstructorKind, Js::JavascriptOperators::IsBaseConstructorKind, AttrCanThrow)
HELPERCALL(Op_LoadHeapArguments, Js::JavascriptOperators::LoadHeapArguments, 0)
Expand Down
1 change: 1 addition & 0 deletions lib/Common/BackendApi.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ enum VTableValue {
VtableDynamicObject,
VtableInvalid,
VtablePropertyString,
VtableLazyJSONString,
VtableLiteralStringWithPropertyStringPtr,
VtableJavascriptBoolean,
VtableJavascriptArray,
Expand Down
11 changes: 11 additions & 0 deletions lib/Common/DataStructures/DList.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,17 @@ class DListCounted : public DList<TData, TAllocator, RealCount>
} \
}

#define FOREACH_DLISTCOUNTED_ENTRY(T, alloc, data, list) \
{ \
DListCounted<T, alloc>::Iterator __iter(list); \
while (__iter.Next()) \
{ \
T& data = __iter.Data();

#define NEXT_DLISTCOUNTED_ENTRY \
} \
}

#define FOREACH_DLIST_ENTRY_EDITING(T, alloc, data, list, iter) \
DList<T, alloc>::EditingIterator iter(list); \
while (iter.Next()) \
Expand Down
2 changes: 1 addition & 1 deletion lib/JITIDL/JITTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ typedef unsigned char boolean;
#define __JITTypes_h__

// TODO: OOP JIT, how do we make this better?
const int VTABLE_COUNT = 48;
const int VTABLE_COUNT = 49;
const int EQUIVALENT_TYPE_CACHE_SIZE = 8;

typedef IDL_DEF([context_handle]) void * PTHREADCONTEXT_HANDLE;
Expand Down
4 changes: 4 additions & 0 deletions lib/Runtime/Base/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ namespace Js
static const size_t GlobalCodeLength = _countof(_u("Global code")) - 1;
static const size_t EvalCodeLength = _countof(_u("eval code")) - 1;
static const size_t UnknownScriptCodeLength = _countof(_u("Unknown script code")) - 1;

static const charcount_t NullStringLength = _countof(_u("Null")) - 1;
static const charcount_t TrueStringLength = _countof(_u("True")) - 1;
static const charcount_t FalseStringLength = _countof(_u("False")) - 1;
};

extern const FrameDisplay NullFrameDisplay;
Expand Down
41 changes: 30 additions & 11 deletions lib/Runtime/Language/JavascriptOperators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1321,31 +1321,35 @@ namespace Js
return type->GetPrototype();
}

BOOL JavascriptOperators::IsArray(Var instanceVar)
BOOL JavascriptOperators::IsArray(_In_ RecyclableObject* instance)
{
if (!RecyclableObject::Is(instanceVar))
{
return FALSE;
}
RecyclableObject* instance = RecyclableObject::FromVar(instanceVar);
if (DynamicObject::IsAnyArray(instance))
{
return TRUE;
}
if (JavascriptProxy::Is(instanceVar))
if (JavascriptProxy::Is(instance))
{
JavascriptProxy* proxy = JavascriptProxy::FromVar(instanceVar);
JavascriptProxy* proxy = JavascriptProxy::FromVar(instance);
return IsArray(proxy->GetTarget());
}
TypeId remoteTypeId = TypeIds_Limit;
if (JavascriptOperators::GetRemoteTypeId(instanceVar, &remoteTypeId) &&
if (JavascriptOperators::GetRemoteTypeId(instance, &remoteTypeId) &&
DynamicObject::IsAnyArrayTypeId(remoteTypeId))
{
return TRUE;
}
return FALSE;
}

BOOL JavascriptOperators::IsArray(_In_ Var instanceVar)
{
if (!RecyclableObject::Is(instanceVar))
{
return FALSE;
}
return IsArray(RecyclableObject::FromVar(instanceVar));
}

BOOL JavascriptOperators::IsConstructor(Var instanceVar)
{
if (!RecyclableObject::Is(instanceVar))
Expand Down Expand Up @@ -10015,9 +10019,14 @@ namespace Js
return JavascriptNumber::ToVarNoCheck(JavascriptConversion::ToNumber_Full(aRight, scriptContext), scriptContext);
}

BOOL JavascriptOperators::IsObject(Var aValue)
BOOL JavascriptOperators::IsObject(_In_ RecyclableObject* instance)
{
return GetTypeId(instance) > TypeIds_LastJavascriptPrimitiveType;
}

BOOL JavascriptOperators::IsObject(_In_ Var instance)
{
return GetTypeId(aValue) > TypeIds_LastJavascriptPrimitiveType;
return GetTypeId(instance) > TypeIds_LastJavascriptPrimitiveType;
}

BOOL JavascriptOperators::IsObjectType(TypeId typeId)
Expand All @@ -10036,6 +10045,11 @@ namespace Js
return IsObjectType(typeId) || typeId == TypeIds_Null;
}

BOOL JavascriptOperators::IsUndefined(_In_ RecyclableObject* instance)
{
return JavascriptOperators::GetTypeId(instance) == TypeIds_Undefined;
}

BOOL JavascriptOperators::IsUndefined(Var instance)
{
return JavascriptOperators::GetTypeId(instance) == TypeIds_Undefined;
Expand Down Expand Up @@ -10378,6 +10392,11 @@ namespace Js

BOOL JavascriptOperators::GetItem(RecyclableObject* instance, uint64 index, Var* value, ScriptContext* requestContext)
{
if (index < JavascriptArray::InvalidIndex)
{
// In case index fits in uint32, we can avoid the (slower) big-index path
return GetItem(instance, static_cast<uint32>(index), value, requestContext);
}
PropertyRecord const * propertyRecord = nullptr;
JavascriptOperators::GetPropertyIdForInt(index, requestContext, &propertyRecord);
return JavascriptOperators::GetProperty(instance, propertyRecord->GetPropertyId(), value, requestContext);
Expand Down
10 changes: 7 additions & 3 deletions lib/Runtime/Language/JavascriptOperators.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ namespace Js
{
// Methods
public:
static BOOL IsArray(Var instanceVar);
static BOOL IsArray(_In_ RecyclableObject* instanceObj);
static BOOL IsArray(_In_ Var instanceVar);
static BOOL IsConstructor(Var instanceVar);
static BOOL IsConcatSpreadable(Var instanceVar);
static RecyclableObject* ToObject(Var aRight,ScriptContext* scriptContext);
Expand Down Expand Up @@ -207,12 +208,15 @@ namespace Js
static BOOL DeletePropertyUnscopables(RecyclableObject* instance, PropertyId propertyId, PropertyOperationFlags propertyOperationFlags = PropertyOperation_None);
template<bool unscopables>
static BOOL DeleteProperty_Impl(RecyclableObject* instance, PropertyId propertyId, PropertyOperationFlags propertyOperationFlags = PropertyOperation_None);
static TypeId GetTypeId(Var instance);
static TypeId GetTypeId(_In_ const Var instance);
static TypeId GetTypeId(_In_ RecyclableObject* instance);
static TypeId GetTypeIdNoCheck(Var instance);
static BOOL IsObject(Var instance);
static BOOL IsObject(_In_ Var instance);
static BOOL IsObject(_In_ RecyclableObject* instance);
static BOOL IsExposedType(TypeId typeId);
static BOOL IsObjectType(TypeId typeId);
static BOOL IsObjectOrNull(Var instance);
static BOOL IsUndefined(_In_ RecyclableObject* instance);
static BOOL IsUndefined(Var instance);
static BOOL IsUndefinedObject(RecyclableObject* instance);
static BOOL IsUndefinedOrNullType(TypeId);
Expand Down
21 changes: 14 additions & 7 deletions lib/Runtime/Language/JavascriptOperators.inl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,19 @@

namespace Js
{
__forceinline TypeId JavascriptOperators::GetTypeId(const Var aValue)
__forceinline TypeId JavascriptOperators::GetTypeId(_In_ RecyclableObject* obj)
{
AssertMsg(obj != nullptr, "GetTypeId aValue is null");

auto typeId = obj->GetTypeId();
#if DBG
auto isExternal = obj->CanHaveInterceptors();
AssertMsg(typeId < TypeIds_Limit || isExternal, "GetTypeId aValue has invalid TypeId");
#endif
return typeId;
}

__forceinline TypeId JavascriptOperators::GetTypeId(_In_ const Var aValue)
{
AssertMsg(aValue != nullptr, "GetTypeId aValue is null");

Expand All @@ -22,12 +34,7 @@ namespace Js
#endif
else
{
auto typeId = RecyclableObject::FromVar(aValue)->GetTypeId();
#if DBG
auto isExternal = RecyclableObject::FromVar(aValue)->CanHaveInterceptors();
AssertMsg(typeId < TypeIds_Limit || isExternal, "GetTypeId aValue has invalid TypeId");
#endif
return typeId;
return JavascriptOperators::GetTypeId(RecyclableObject::FromVar(aValue));
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Runtime/Library/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ set(CRLIB_SOURCE_CODES
JSONScanner.cpp
JSONStack.cpp
JSONString.cpp
JSONStringBuilder.cpp
JSONStringifier.cpp
JavascriptArray.cpp
JavascriptArrayIndexEnumerator.cpp
JavascriptArrayIndexEnumeratorBase.cpp
Expand Down Expand Up @@ -101,6 +103,7 @@ set(CRLIB_SOURCE_CODES
JavascriptVariantDate.cpp
JavascriptWeakMap.cpp
JavascriptWeakSet.cpp
LazyJSONString.cpp
LiteralString.cpp
MathLibrary.cpp
ModuleRoot.cpp
Expand Down
6 changes: 6 additions & 0 deletions lib/Runtime/Library/Chakra.Runtime.Library.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@
<ClCompile Include="$(MSBuildThisFileDirectory)CustomExternalIterator.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)JavascriptExceptionMetadata.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)VerifyMarkFalseReference.cpp" />
<ClCompile Include="JSONStringBuilder.cpp" />
<ClCompile Include="JSONStringifier.cpp" />
<ClCompile Include="LazyJSONString.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\DetachedStateBase.h" />
Expand All @@ -193,6 +196,9 @@
<ClInclude Include="JavascriptSimdBool32x4.h" />
<ClInclude Include="JavascriptSimdBool16x8.h" />
<ClInclude Include="JavascriptSimdBool8x16.h" />
<ClInclude Include="JSONStringBuilder.h" />
<ClInclude Include="JSONStringifier.h" />
<ClInclude Include="LazyJSONString.h" />
<ClInclude Include="SharedArrayBuffer.h" />
<ClInclude Include="SimdFloat32x4Lib.h" />
<ClInclude Include="SimdFloat64x2Lib.h" />
Expand Down
6 changes: 6 additions & 0 deletions lib/Runtime/Library/Chakra.Runtime.Library.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<ClCompile Include="$(MSBuildThisFileDirectory)WabtInterface.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)CustomExternalIterator.cpp" />
<ClCompile Include="$(MSBuildThisFileDirectory)VerifyMarkFalseReference.cpp" />
<ClCompile Include="LazyJSONString.cpp" />
<ClCompile Include="JSONStringifier.cpp" />
<ClCompile Include="JSONStringBuilder.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\InternalPropertyList.h" />
Expand Down Expand Up @@ -259,6 +262,9 @@
<ClInclude Include="CustomExternalIterator.h" />
<ClInclude Include="JavascriptExceptionMetadata.h" />
<ClInclude Include="..\DetachedStateBase.h" />
<ClInclude Include="LazyJSONString.h" />
<ClInclude Include="JSONStringifier.h" />
<ClInclude Include="JSONStringBuilder.h" />
</ItemGroup>
<ItemGroup>
<None Include="ConcatString.inl" />
Expand Down
Loading

0 comments on commit f10138e

Please sign in to comment.