Skip to content
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

http: improve performance by removing async_hooks #57746

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JonasBa
Copy link
Contributor

@JonasBa JonasBa commented Apr 4, 2025

Pending benchmarks, but this should improve http request performance.

Github search results for HTTPIncomingMessage and HTTPClientRequest

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/http
  • @nodejs/net

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. http_parser Issues and PRs related to the HTTP Parser dependency or the http_parser binding. needs-ci PRs that need a full CI run. labels Apr 4, 2025
@anonrig anonrig requested a review from jasnell April 4, 2025 15:25
@mcollina
Copy link
Member

mcollina commented Apr 4, 2025

Pending positive benchmarks, I’m in favor of this change as the http parser does not have inherent asynchronous behavior and it’s all sync.

@jasnell jasnell added the needs-benchmark-ci PR that need a benchmark CI run. label Apr 4, 2025
env()->context(), object(), 0, nullptr);

if (r.IsEmpty()) callback_scope.MarkAsFailed();
USE(cb.As<Function>()->Call(env()->context(), object(), 0, nullptr));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should avoid using USE(...) here as it does not allow thrown errors to propagate correctly here. Note the previous code had the check for IsEmpty() and setting MarkAsFailed... that behavior should be retained.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there aren't any such tests already, a test verifying that errors thrown in HTTPParser callbacks are handled correctly would be helpful in verifying the changed behavior here.

if (head_response.IsEmpty()) callback_scope.MarkAsFailed();
}
MaybeLocal<Value> head_response = cb.As<Function>()->Call(
env()->context(), object(), arraysize(argv), argv);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise here, this is not properly handling errors.

@@ -575,11 +556,6 @@ class Parser : public AsyncWrap, public StreamListener {
static void Free(const FunctionCallbackInfo<Value>& args) {
Parser* parser;
ASSIGN_OR_RETURN_UNWRAP(&parser, args.This());

// Since the Parser destructor isn't going to run the destroy() callbacks
// it needs to be triggered manually.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need this function anymore.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. http_parser Issues and PRs related to the HTTP Parser dependency or the http_parser binding. needs-benchmark-ci PR that need a benchmark CI run. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants