v8: add setHeapProfileNearHeapLimit#64676
Conversation
Signed-off-by: ishabi <ilyasshabi94@gmail.com>
| env, | ||
| }); | ||
| console.log(child.stdout.toString()); | ||
| console.log(child.stderr.toString()); |
There was a problem hiding this comment.
Are the console.log(...) log statements necessary for the test? If not, can we remove them? If they are, can you add a comment?
|
I struggle to see how this API can ever stabilize - what one can do when the heap is near the heap limit is very limited, and in particular if you do too much in the callback to incur another allocation, the program would be in a very unstable state. Our current callbacks only do very limited things within the C++, allowing users to do arbitrary things in JS sounds like an API that invites bugs...I think a safer option would be to only write a profile when it reaches the limit, though even then I am not sure how well the profiler works when the heap is about to reach the limit... |
|
I'm also wary on adding a JS callback to be invoked at new heap limit. This callback also takes a heap profile parameter which is taken on a big heap, sounds like exacerbating the problem it wants to fix. |
|
|
||
| v8.startHeapProfile(); | ||
| v8.setHeapProfileNearHeapLimit((profile) => { | ||
| console.log(JSON.parse(profile)); |
There was a problem hiding this comment.
This example asks users to exacerbating the heap usages when the heap is near limit...
Adds
v8.setHeapProfileNearHeapLimit(onProfile, options)API that captures the active sampling heap profile when V8 is near the heap limit and delivers it to a JS callback. This is complementsv8.setHeapSnapshotNearHeapLimitfor observability use cases that want the sampled allocation profile rather than a full heap snapshot at OOM time.This new API requires
v8.startHeapProfile()to have been called before.Both
setHeapProfileNearHeapLimitandsetHeapSnapshotNearHeapLimitcan be active on the same isolate.