-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Callbacks for async/await #40
Comments
@mwaldrich Hi, thanks for the suggestion here. For For For With these two callbacks, you should be able to know if an async function has been awaited by tracking if any await is waiting for the same promiseObject returned by the async function. I had some experimental implementation about the callbacks as above. However, it was based on my own hack on an old version of Graal.js. We will look into how to properly integrate it in Graal.js in future. Feel free to discuss here what you think about these potential new callbacks. |
Sounds great! This should be enough to perform general instrumentation on async/await in JS. How much work will it be to clean up the hacky implementation and get it merged into Graal? |
Any update on these callbacks? |
Async support has been merged upstream thanks to @eleinadani, await is still in progress. |
Thanks for the implementation! I've started playing around with these callbacks, but they don't seem to be called in the way I would expect. I actually have two concerns:
Example (timing how long each await is)Imagine you want to write a simple analysis to time how long each await is. You want to record a timestamp when a value is awaited, and another when the await is resolved. Here's a simple analysis and sample program.
|
I will look into the issue, thanks for the feedback! |
Also, a few more things I noticed:
|
I have tried using the new However, the To do this, the
|
In Graal.js we can already instrument all |
@mwaldrich It makes sense to add the promise object also in the awaitPost statement. I think you can maintain an id for a promise object in your analysis using the builtin @eleinadani I think it's not related to the builtins. We can provide the promise object from the inputs. I will patch nodeprof to do it. |
@mwaldrich actually adding the promise object in awaitPost might not be necessary. Since now awaitPre and |
@Haiyang-Sun Even though awaitPre/awaitPost appear in pairs, I don't think they can be tracked in a stack. I think this is because async/await programs, just like ES5 programs with native promises, have dynamic control flow that doesn't fit into a simple call-stack model. The program can be waiting on multiple independent awaits, and the processing order depends on the event loop. Here's an example of a program whose awaitPre/awaitPosts do not form a stack:
|
@mwaldrich Umm, I know that providing a promise would be helpful. But it is not the key to the problem here. Assume the following example:
You will still have the same promise object in the two awaitPost events. |
@Haiyang-Sun I see what you're saying, but I think neither queues nor stacks will work. Functions like those in the Here's an example of code that (usually) doesn't process its awaits as a queue:
|
Yeah, you are right. So we might actually need a unique id for the await operation. |
Yes, there should be an internal promise and you should be able to instrument that via builtin root nodes instrumentation. Regarding unique ids, I think you can just use |
Is there any update on the implementation of the modified |
@mwaldrich Sorry for the late reply. I had a look, it is not straightforward to update this feature. I can work on it later this week. |
@mwaldrich I have a workaround fix (#70). Another special case is to await on a value instead of a promise. You won't get any promise object in the callbacks. There is still a bug where we can miss the promise object in the |
Would it be possible to implement new callbacks to instrument
async
andawait
?For
async
, perhaps an argument could be added to the function call and function literal callbacks to indicate if it is anasync
function.For
await
, I would suggest:isAwaited
argument to the function call callbacks, indicating that the caller is awaiting this function's result.await
callback. This would allow the analysis to instrument when theawait
is scheduled.These three changes together will allow analysis to distinguish between:
Thanks!
The text was updated successfully, but these errors were encountered: