Description
While developing dprof I came to realize that using beforeTimestamp (pre hook) - initTimestamp (init hook)
as an async duration estimate is a bit misleading.
For example if user create a timeout of 100 ms
and in the meanwhile have a cpu hungry calculation there takes 200 ms
. The async operation only takes 100 ms
but the beforeTimestamp - initTimestamp
would indicate 200 ms
.
A bit more likely, user could do fs.open
which would finish quickly, but have so many other callbacks there needs calling first that it would take much longer time before the fs.open
callback is called.
In both cases it would look like the async operation took much longer than it actually did. The user would ask questions like "why did my timeout take 200 ms, when I set it to 100 ms?" or "why is my filesystem so slow?".
I don't known if it is possible but I think a asyncReady
event is missing. This would emit when the async operation is done. I'm guessing there is some interrupt causing a push the job queue that one could listen on, but I don't know. Emitting the event immediately would be problematic, as the javascript program would jump in a sync state. So I guess asyncReady
it will just have to be executed right after the current callback is done. This would fix the fs.open
example, but not the setTimeout
example.
Activity