Skip to content

Add funcitonality to take heap snapshots#1545

Draft
kulcsaradam wants to merge 1 commit intoSamsung:masterfrom
kulcsaradam:heapsnapshot
Draft

Add funcitonality to take heap snapshots#1545
kulcsaradam wants to merge 1 commit intoSamsung:masterfrom
kulcsaradam:heapsnapshot

Conversation

@kulcsaradam
Copy link

No description provided.


// [["hidden","array","string","object","code","closure","regexp","number","native","synthetic","concatenated string","sliced string","symbol","bigint","object shape"],"
// "edge_types":[["context","element","property","internal","hidden","shortcut","weak"]
uint64_t stateIdx = addNode(info, snapshotNode::hidden, "state", &id, sizeof(*state), false);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Introduce a local lambda that takes the node type, name, size, and parent index, calls addNode, and immediately adds an edge of type snapshotEdge::element. This reduces the repeated pattern of addNode(...); addEdge(...); and makes the intent clearer. The lambda can be defined near the top of the case block and used for each node addition. This keeps the code concise and easier to maintain.

Signed-off-by: Ádám László Kulcsár <kuladam@inf.u-szeged.hu>
@kulcsaradam
Copy link
Author

@ksh8281 could you give some pointers about what types of Escargot internals should the snapshot 100% contain?

Currently, I've implemented tracking for simple constructs, such as the state, lexical environments and some of their members, but is very rudimentary so far. Should each member of an object be tracked or would that be unnecesarry?

For example for some simple javascript like this:

function smthing() {
  return 2;
}

{
  var a = 3;
  print(smthing() + a);
}

The produced snapshot when viewed in chrome devtools looks like this:
image

(I also included the snapshot as json. The file extension needs to be changed into .heapsnapshot to work with chrome dev tools though, but github does not allow such files to be uploaded)
output.json

This basic example contains 99 objects (most of which are strings that are properties of the global object) and every object can be reached from the "root" which is the ExecutionState object in this case.

@ksh8281
Copy link
Contributor

ksh8281 commented Mar 13, 2026

The first result is excellent.
In my opinion, we need to track object members :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants