console icon indicating copy to clipboard operation
console copied to clipboard

`console.takeHeapSnapshot` is available in some browsers

Open JosephPecoraro opened this issue 7 years ago • 8 comments

console.takeHeapSnapshot is available in some browsers, so it should be standardized.

Edge had it originally and describe it in their documentation here and over here for debugging JavaScript Memory in the browser and apps. When Safari/WebKit added Memory Debugging they adopted the same name and semantics. It was described briefly in a webkit.org blog post.

  • Edge: Supported. (Since Version ?)
  • Safari: Supported. (Since Version 10.0)
  • Firefox: Not supported. Bug 960662
  • Chrome: Not supported. Bug 448379

Proposal:

interface Console {
    void takeHeapSnapshot(optional DOMString label);
};

Using console.takeHeapSnapshot without a label is fine. User agents can just give their own label such as Snapshot 1, Snapshot 2, etc. When providing a label developer tools can decide to show that label in their user interface if they wish. Labels can give useful context information for users using the API. For example Snapshot 1 – Before Operation, Snapshot 2 – After Operation.

JosephPecoraro avatar Dec 07 '16 20:12 JosephPecoraro

As the PM for Edge Devtools, I'd be happy to see this land in the spec.

auchenberg avatar Dec 07 '16 21:12 auchenberg

I'm not 100% sure what implications this would have for Node.js, I don't think Heap Snapshots are currently programatically available or where we would put them, but It could be possible.

This doesn't really seem related to the console though?

Fishrock123 avatar Dec 19 '16 23:12 Fishrock123

Yeah, it's a bit surprising that this is on console, but apparently it is, so we should spec it so that people don't write code that only works in some environments.

It sounds like there might be a case for saying "if possible, or do nothing" (similar to clear) though.

A "heap snapshot" for Node might look something like https://nodejs.org/dist/latest-v7.x/docs/api/process.html#process_process_memoryusage , but given that there's no "dev tools timeline" to display them on, and this doesn't seem to print anything, maybe it's best that it just be a no-op in Node.

domenic avatar Dec 19 '16 23:12 domenic

Would it be an option to not spec it and recommend moving those users to a better API? Could we get some ecosystem usage stats?

Fishrock123 avatar Dec 19 '16 23:12 Fishrock123

I think having it on console just follows the precedent of profile, profileEnd, and timeStamp. It just so happens that console is the namespace where new Web APIs have gone that programmatically interact with browser developer tools. It is not surprising that these are the ones that Node doesn't include on their console object which is more geared toward some kind of real console.

console.timeStamp could be considered similar / identical to performance.mark. Maybe there could be a new place for these other commands instead of console? Moving would be inconvenient but not impossible.

That said, I don't think there is much to spec here other than the interface.

JosephPecoraro avatar Dec 20 '16 06:12 JosephPecoraro

A big (>100MB) WebAssembly module throws "Out of memory" error in Safari after several subsequent page reloads. Calling the console.takeHeapSnapshot() function in the unload event handler helps because it triggers garbage collection.

Having the function standardized (or at least WebKit folks have fixed the bug) would provide a better stability for WebAssembly use on Web.

avesus avatar Jan 22 '19 06:01 avesus

Since now Safari is the only implementation for takeHeapSnapshot, maybe close this?

saschanaz avatar Sep 20 '21 01:09 saschanaz

We generally leave feature proposal issues open unless they are definitively shut down by 2/3 implementers.

domenic avatar Sep 20 '21 14:09 domenic