console
console copied to clipboard
`console.takeHeapSnapshot` is available in some browsers
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
.
As the PM for Edge Devtools, I'd be happy to see this land in the spec.
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?
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.
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?
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.
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.
Since now Safari is the only implementation for takeHeapSnapshot, maybe close this?
We generally leave feature proposal issues open unless they are definitively shut down by 2/3 implementers.