-
Notifications
You must be signed in to change notification settings - Fork 7
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
Node errors are very slow to create #40
Comments
I’m aware of this, and it’s on my to-do list. Appreciate any experiences and/or thoughts on this! |
I want to talk about it next meeting. I have some ideas. |
This is really problematic. I would recommend we include also @jasnell and maybe we schedule a custom meeting for this. There is a lot to talk about. |
FWIW I have an open PR that makes Error creation slower, but also less vulnerable. I guess it'd be nice to see if there's a way to make both things happen or if those are two conflicting goals. |
I am currently looking into improving the performance. So far I have identified two things that we are able to improve. We are able to move some checks from the runtime to the setup time. This is however only a small part of the overall performance overhead. One big bottleneck is Besides the actual performance bottleneck, the implementation itself has become difficult to maintain by now as we have lots of very similar functions that create things slightly different. I am working on unifying that but it is going to take some time to do this right. |
One note on |
@BridgeAR a quick analysis on my end showed that the bottleneck for generic errors (such as |
Yeah the internal/errors.js situation is... Unfortunate. Tons more complexity has evolved there than was originally intended. |
We can't remove stack traces usually (in stuff like AbortError) as it significantly harms debugging. The workaround is to capture them lazily like "regular" errors and move to more standard errors like @mcollina suggests IMO. |
I already implemented some first improvements locally:
|
I checked AbortError again and it seems like the stack trace is needed in most cases to allow users to identify the point where they called There are a few places where it's possible to remove the stack frames such as when running in a timeout ( The errors are just slow as long as we have to collect the stack frames and we should probably keep that behavior as it is. |
Just to keep things tracked, currently, we have these PRs addressing this issue:
Except for the first, all of them were made by @Uzlopak. The first one brings a lot of improvements but hasn't had any activity in months, @BridgeAR do you need any help? Probably these new changes made by Uzlopak will bring a lot of conflicts, and maybe some of the optimizations will overlap with the changes made by BridgeAR, if we don't receive updates from BridgeAR, I suggest creating new smaller PRs using the first PR as a base just to not lose these big improvements. @anonrig I think it's worth adding this issue back to the agenda just to discuss current improvements (if that's enough to close this issue) and what we can do with #46648 |
Created now also as first step to improve SystemError instanciation. |
I think i found a somewhat elegant way to change hideStackframe so that we dont need to patch the name of the function, and the need to handle those in prepareStackTrace. It should then also make the use of captureLargerStackTrace obsolete. On the long run, I try to avoid providing a custom prepareStackTrace, and stack trace output should then be based solely on v8. But i cant promise that. One obstacle at a time. Stay tuned. |
Sooo. Created my proposal: nodejs/node#49990 |
Since I see it's still open ... just adding a droplet (though that crossed my mind) ... which you might alreay have though of and discarded but since I don't see it discussed here : Or even just an option that'd be like "enhance performance at the cost of debugging ease in the stacktrace" ? This way we could get the best of both world ... and in case we'd need debugging in prod ... we could also ... at the cost of reduced performance ... but it'd be temporary, ideally ... |
You can set it via a cli flag: If you set it to 0, than it gets really fast |
Unfortunately, it's becoming increasingly common that errors are used as part of normal control flow.
AbortController
throws anAbortError
as part of cancellation logic.res.statusCode = 404; res.end(); return;
.Hence the current state of constructing errors in Node is not optimal. The errors are heavily enriched with lots of helpful information, however at a huge performance cost. We need to investigate what can be done to improve this and discuss possible compromises.
The text was updated successfully, but these errors were encountered: