Skip to content

Commit 0c7acf8

Browse files
committed
OS#17588837 - Fast memory growth when serializing many ScopeInfo objects
Change ByteCodeSerializer to serialize unique ScopeInfo objects only once instead of duplicating them in the serialized bytecode. This was causing some websites to allocate quite a bit of memory due to them referencing the same huge ScopeInfo objects many times. Fixes: https://microsoft.visualstudio.com/web/wi.aspx?id=17588837
1 parent 89603db commit 0c7acf8

File tree

10 files changed

+31093
-30941
lines changed

10 files changed

+31093
-30941
lines changed

lib/Runtime/ByteCode/ByteCodeSerializer.cpp

Lines changed: 167 additions & 24 deletions
Large diffs are not rendered by default.

lib/Runtime/ByteCode/ByteCodeSerializer.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ namespace Js
100100
SerializedFuncInfoArray(uint offset, int count);
101101
};
102102

103+
typedef uint LocalScopeInfoId;
104+
103105
#pragma pack(pop)
104106

105107
// Holds information about the deserialized bytecode cache. Contains fast inline functions
@@ -111,12 +113,17 @@ namespace Js
111113
PropertyId * propertyIds;
112114
int propertyCount;
113115
int builtInPropertyCount;
116+
uint scopeInfoCount;
117+
const byte** scopeInfoRelativeOffsets;
114118

115119
typedef JsUtil::BaseDictionary<Js::LocalFunctionId, FunctionInfo*, ArenaAllocator> LocalFunctionIdToFunctionInfoMap;
116120
LocalFunctionIdToFunctionInfoMap* localFunctionIdToFunctionInfoMap;
121+
typedef JsUtil::BaseDictionary<LocalScopeInfoId, ScopeInfo*, ArenaAllocator> LocalScopeInfoIdToScopeInfoMap;
122+
LocalScopeInfoIdToScopeInfoMap* localScopeInfoIdToScopeInfoMap;
117123

118124
private:
119125
LocalFunctionIdToFunctionInfoMap * EnsureLocalFunctionIdToFunctionInfoMap(ScriptContext * scriptContext);
126+
LocalScopeInfoIdToScopeInfoMap * EnsureLocalScopeInfoIdToScopeInfoMap(ScriptContext * scriptContext);
120127

121128
public:
122129
ByteCodeCache(ScriptContext * scriptContext, int builtInPropertyCount);
@@ -127,6 +134,7 @@ namespace Js
127134

128135
void RegisterFunctionIdToFunctionInfo(ScriptContext * scriptContext, LocalFunctionId functionId, FunctionInfo* functionInfo);
129136
FunctionInfo* LookupFunctionInfo(ScriptContext * scriptContext, LocalFunctionId functionId);
137+
ScopeInfo* LookupScopeInfo(ScriptContext * scriptContext, LocalScopeInfoId scopeInfoId);
130138

131139
ByteCodeBufferReader* GetReader()
132140
{

lib/Runtime/Library/InJavascript/Intl.js.bc.32b.h

Lines changed: 7577 additions & 7577 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.bc.64b.h

Lines changed: 7576 additions & 7576 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.32b.h

Lines changed: 6896 additions & 6895 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/InJavascript/Intl.js.nojit.bc.64b.h

Lines changed: 6895 additions & 6895 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.bc.32b.h

Lines changed: 508 additions & 508 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.bc.64b.h

Lines changed: 508 additions & 508 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.nojit.bc.32b.h

Lines changed: 479 additions & 479 deletions
Large diffs are not rendered by default.

lib/Runtime/Library/JsBuiltIn/JsBuiltIn.js.nojit.bc.64b.h

Lines changed: 479 additions & 479 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)