-
Notifications
You must be signed in to change notification settings - Fork 78
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
Proposal for Promise hooks to improve performance. #188
Comments
"You need permission" - is that intentional? |
@hashseed I think you need to make the document public. |
Ah yeah. Totally forgot. Thanks. |
As discussed during the WG meeting, @mcollina is going to reach out to find out why async hooks were designed around async IDs and whether adding the resource would be ok. |
Definitely a 👍 from me. There's no reason for all this work to be done on the native side. No one uses it there. One thing I'd like to bring up, which I think is relevant, and I have commented on several times in the past is that async_hooks and the previous iteration in AsyncListener both made the mistake of conflating resource lifecycle with asynchronous boundary linkage. I think that has long been a major failing, preventing the feature from working optimally. Some want to track the resource lifecycle, which makes sense for exhaustible resources like sockets and file descriptors. However, that really doesn't make sense for something like promise hooks. Promises are not an exhaustible resource, the object itself is not actually relevant. For asynchronous continuity, it's actually the callback that we care about--namely, linking where it was declared to where it was executed. I feel like it would have made a lot more sense to have one system which tracks creation and destruction of true resource handles, and then a completely separate feature used exclusively for connecting async task init points to the callback start and end. Resources would generally need native code to track those lifecycle points, but the barrier tracking can be implemented 100% in JS. (I actually wrote exactly this as an experiment several years ago. https://github.com/qard/stacks-concept) |
I'm -1. Maybe this is the correct approach, but it completly skips over the memory issues that have been reported. I think the memory issue is actually what we have gotten most uninfluced feedback about (feedback where we didn't ask directly, "what is the performance overhead"). In fact two companies have reached out to me personally about memory issues, non about computationally issues. There are also some issues: I remember there being more, but perhaps they are not in nodejs/node.
Two reasons: Reason 1: The destoy hook was added because the rest isn't always enogth information. It would allow you to:
If you want to get meta information from the Reason 2: WeekMap have a very bad memory profile. In AndreasMadsen/trace#17 someone reported that require('trace')
var stream = require('fs').createReadStream('huge file here')
stream.resume() Turns out that WeakMap are really bad for memory consumtion, especially in cases where you get a very determinstic Removing the destroy hook and using WeakMaps means that we can't efficiently cleanup after I also understand that to more efficiently garbage collect promises in the future, using ecape-analysis, we can't depend on the |
I haven't had time to prepare response for your entire answer, which btw is very detailed, thanks. Just some thoughts:
|
We don't need to expose the
In C++ we only use the promise object for assigning I have said this quite a few times, I think most details is in here: nodejs/benchmarking#181 (comment) and comments futher down.
Should be fine. The |
While it doesn't make any difference now. In the future PromiseHooks could be refactored to provide an asyncId instead of the promise object. That would make escape analysis on promises possible. Escape analysis on promises could lead to a more efficient destroy hook, if provide by PromiseHooks as well. But at the very least would allow the destroy hook to be emitted earlier. The destroy hook not being emitted on promises frequent enough is a known and reported issue. See nodejs#14446 and Jeff-Lewis/cls-hooked#11. While all this is speculation for now, it all depends on the promise object not being a part of the PromiseWrap resource object. Ref: nodejs#14446 Ref: nodejs/diagnostics#188
While it doesn't make any difference now. In the future PromiseHooks could be refactored to provide an asyncId instead of the promise object. That would make escape analysis on promises possible. Escape analysis on promises could lead to a more efficient destroy hook, if provide by PromiseHooks as well. But at the very least would allow the destroy hook to be emitted earlier. The destroy hook not being emitted on promises frequent enough is a known and reported issue. See #14446 and Jeff-Lewis/cls-hooked#11. While all this is speculation for now, it all depends on the promise object not being a part of the PromiseWrap resource object. Ref: #14446 Ref: nodejs/diagnostics#188 PR-URL: #23443 Refs: #14446 Refs: nodejs/diagnostics#188 Reviewed-By: Benedikt Meurer <benedikt.meurer@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: George Adams <george.adams@uk.ibm.com>
This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made. |
@Qard do you want to keep this issue opened? |
Everything that can be done from Node.js perspective has already been done, so I think it can be closed. It would still be nice to have V8 supply a version of the API which takes It may also be worth looking into skipping non-observable promises, though it seems like the V8 folks have actually just tried to eliminate some of those altogether since the doc for that issue was originally written. Not sure how relevant that last idea is at this point. |
@bmeurer, @ofrobots and I discussed and put some thoughts together. Comments welcome!
The text was updated successfully, but these errors were encountered: