Skip to content

Commit

Permalink
fix(core): simplify serialization for code heap object (#122)
Browse files Browse the repository at this point in the history
Summary:
MemLab could run out of memory if the JS heap under analysis has complex code heap objects (i.e., JS interpreted, and compiled code representation and their context graph in heap) which may take a lot of time and memory to serialize:
#122

This diff fixes this issue by simplifying the code heap object serialization process and output.

Reviewed By: tulga1970

Differential Revision: D59541476

fbshipit-source-id: a4eb00e0f914d4694a1fe562abe0c861ca641ad1
  • Loading branch information
JacksonGL authored and facebook-github-bot committed Jul 10, 2024
1 parent 14f047d commit f2af467
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
4 changes: 4 additions & 0 deletions packages/core/src/lib/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export class MemLabConfig {
maxSamplesForClustering: number;
filterTraceByName: Nullable<string>;
skipBrowserCloseWait: boolean;
simplifyCodeSerialization: boolean;

constructor(options: ConfigOption = {}) {
// init properties, they can be configured manually
Expand Down Expand Up @@ -375,6 +376,9 @@ export class MemLabConfig {
this.filterTraceByName = null;
// if true, memlab will not wait for the browser to close successfully
this.skipBrowserCloseWait = false;
// if true, serialized leak trace will have a simplified representation
// for code object, which could be large and cause OOM during serualization
this.simplifyCodeSerialization = !constant.isFB;
}

// initialize configurable parameters
Expand Down
9 changes: 7 additions & 2 deletions packages/core/src/lib/Serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,23 @@ function JSONifyCode(
options: JSONifyOptions,
): ISerializedInfo {
const info = Object.create(null);

iterateSelectedEdges(node, (edge: IHeapEdge): Optional<{stop: boolean}> => {
if (
edge.name_or_index === 'name_or_scope_info' &&
edge.toNode.name === '(function scope info)'
) {
const key = 'variables with non-number values in closure scope chain';
info[key] = JSONifyNode(edge.toNode, args, options);
info[key] = config.simplifyCodeSerialization
? JSONifyNodeOneLevel(edge.toNode)
: JSONifyNode(edge.toNode, args, options);
} else if (edge.name_or_index === 'script_or_debug_info') {
info['script URL'] = edge.toNode.name;
} else {
const key = filterJSONPropName(edge.name_or_index);
info[key] = JSONifyNode(edge.toNode, args, options);
info[key] = config.simplifyCodeSerialization
? JSONifyNodeOneLevel(edge.toNode)
: JSONifyNode(edge.toNode, args, options);
}
return null;
});
Expand Down

0 comments on commit f2af467

Please sign in to comment.