Skip to content

Commit f8023f7

Browse files
Implemented StringTemplate Caching based on location in source Code.
Changed the earlier implementation of caching the StringTemplates based on Raw String Literals to their location in the source code.
1 parent 50e23bd commit f8023f7

File tree

6 files changed

+58
-472
lines changed

6 files changed

+58
-472
lines changed

lib/Runtime/ByteCode/ByteCodeEmitter.cpp

+6-13
Original file line numberDiff line numberDiff line change
@@ -5692,20 +5692,13 @@ void ByteCodeGenerator::RecordAllStringTemplateCallsiteConstants(FuncInfo* funcI
56925692
funcInfo->stringTemplateCallsiteRegisterMap.Map([byteCodeFunction](ParseNodePtr pnode, Js::RegSlot location)
56935693
{
56945694
Js::ScriptContext* scriptContext = byteCodeFunction->GetScriptContext();
5695-
Js::JavascriptLibrary* library = scriptContext->GetLibrary();
5696-
Js::RecyclableObject* callsiteObject = library->TryGetStringTemplateCallsiteObject(pnode);
5697-
5698-
if (callsiteObject == nullptr)
5699-
{
5700-
Js::RecyclableObject* rawArray = ByteCodeGenerator::BuildArrayFromStringList(pnode->AsParseNodeStrTemplate()->pnodeStringRawLiterals, pnode->AsParseNodeStrTemplate()->countStringLiterals, scriptContext);
5701-
rawArray->Freeze();
5702-
5703-
callsiteObject = ByteCodeGenerator::BuildArrayFromStringList(pnode->AsParseNodeStrTemplate()->pnodeStringLiterals, pnode->AsParseNodeStrTemplate()->countStringLiterals, scriptContext);
5704-
callsiteObject->SetPropertyWithAttributes(Js::PropertyIds::raw, rawArray, PropertyNone, nullptr);
5705-
callsiteObject->Freeze();
5695+
5696+
Js::RecyclableObject* rawArray = ByteCodeGenerator::BuildArrayFromStringList(pnode->AsParseNodeStrTemplate()->pnodeStringRawLiterals, pnode->AsParseNodeStrTemplate()->countStringLiterals, scriptContext);
5697+
rawArray->Freeze();
57065698

5707-
library->AddStringTemplateCallsiteObject(callsiteObject);
5708-
}
5699+
Js::RecyclableObject* callsiteObject = ByteCodeGenerator::BuildArrayFromStringList(pnode->AsParseNodeStrTemplate()->pnodeStringLiterals, pnode->AsParseNodeStrTemplate()->countStringLiterals, scriptContext);
5700+
callsiteObject->SetPropertyWithAttributes(Js::PropertyIds::raw, rawArray, PropertyNone, nullptr);
5701+
callsiteObject->Freeze();
57095702

57105703
byteCodeFunction->RecordConstant(byteCodeFunction->MapRegSlot(location), callsiteObject);
57115704
});

lib/Runtime/ByteCode/ByteCodeSerializer.cpp

+1-10
Original file line numberDiff line numberDiff line change
@@ -3210,16 +3210,7 @@ class ByteCodeBufferReader
32103210
callsite->SetPropertyWithAttributes(Js::PropertyIds::raw, rawArray, PropertyNone, nullptr);
32113211
callsite->Freeze();
32123212

3213-
JavascriptLibrary* library = scriptContext->GetLibrary();
3214-
3215-
var = library->TryGetStringTemplateCallsiteObject(callsite);
3216-
3217-
if (var == nullptr)
3218-
{
3219-
library->AddStringTemplateCallsiteObject(callsite);
3220-
var = callsite;
3221-
}
3222-
3213+
var = callsite;
32233214
LEAVE_PINNED_SCOPE();
32243215

32253216
return current;

lib/Runtime/ByteCode/FuncInfo.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class FuncInfo
146146
typedef JsUtil::BaseDictionary<double,Js::RegSlot, ArenaAllocator, PrimeSizePolicy> DoubleRegisterMap;
147147
DoubleRegisterMap doubleConstantToRegister; // maps double constant to register
148148

149-
typedef JsUtil::BaseDictionary<ParseNodePtr, Js::RegSlot, ArenaAllocator, PowerOf2SizePolicy, Js::StringTemplateCallsiteObjectComparer> StringTemplateCallsiteRegisterMap;
149+
typedef JsUtil::BaseDictionary<ParseNodePtr, Js::RegSlot, ArenaAllocator, PowerOf2SizePolicy> StringTemplateCallsiteRegisterMap;
150150
StringTemplateCallsiteRegisterMap stringTemplateCallsiteRegisterMap; // maps string template callsite constant to register
151151

152152
Scope *paramScope; // top level scope for parameter default values

0 commit comments

Comments
 (0)