First off, a thank you @littledan for pointing me at this proposal. Overall I think it's a great start and a great addition to the API surface here. It should be fairly straightforward to implement support for this in Node.js and definitely think it's something we would do.
A couple of comments on the API... May have more later but these are what jumps out immediately.
-
An alternative to specifying a sample interval would be to specify a sample rate ... for instance, something like await performance.profile({ hz: 20 }) (sample at approximately 20 samples per second).
-
The ProfilerTrace object can potentially be a bit heavy in terms of memory load. It would be very interesting to support a streaming mode as an alternative that just outputs a raw stream of profile data rather than building up the index. Imagine an API like...
const profiler = await performance.profile({ sampleInterval: 10 });
for (let i = 0; i < 1000000; i++) {
doWork();
}
profiler.stop();
sendTrace(await profiler.trace()); // returns the parsed `ProfilerTrace`
// alternatively
const profiler = await performance.profile({ sampleInterval: 10 });
profiler.reader().pipeTo(writable); // Consumes the profile as a raw stream of events
for (let i = 0; i < 1000000; i++) {
doWork();
}
profiler.stop();
The stream approach would generate more raw unprocessed data but would allow it to be piped out and processed later much more efficiently.
First off, a thank you @littledan for pointing me at this proposal. Overall I think it's a great start and a great addition to the API surface here. It should be fairly straightforward to implement support for this in Node.js and definitely think it's something we would do.
A couple of comments on the API... May have more later but these are what jumps out immediately.
An alternative to specifying a sample interval would be to specify a sample rate ... for instance, something like
await performance.profile({ hz: 20 })(sample at approximately 20 samples per second).The
ProfilerTraceobject can potentially be a bit heavy in terms of memory load. It would be very interesting to support a streaming mode as an alternative that just outputs a raw stream of profile data rather than building up the index. Imagine an API like...The stream approach would generate more raw unprocessed data but would allow it to be piped out and processed later much more efficiently.