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: use v8::Array::New() with a prebuilt vector #46447

Merged
merged 3 commits into from
Feb 8, 2023

Conversation

joyeecheung
Copy link
Member

Avoid using v8::Array::Set() which results in JS execution and is thus slow. Prebuild the vector in C++ land and build the JS array directly with that vector whereever possible.

Avoid using v8::Array::Set() which results in JS execution and is
thus slow. Prebuild the vector in C++ land and build the
JS array directly with that vector whereever possible.
@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 Jan 31, 2023
@nodejs-github-bot

This comment was marked as outdated.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

@nodejs-github-bot
Copy link
Collaborator

ConnectionsList* list;

ASSIGN_OR_RETURN_UNWRAP(&list, args.Holder());

uint32_t i = 0;
std::vector<Local<Value>> result;
Copy link
Member

Choose a reason for hiding this comment

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

What about using MaybeStackBuffer to avoid allocations if number of elements is not too high?

Copy link
Member Author

@joyeecheung joyeecheung Feb 4, 2023

Choose a reason for hiding this comment

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

I think v8::Array -> std::vector would make sense (to avoid C++ -> JS invocation costs) but std::vector -> MaybeStackBuffer probably would not make much difference...(and personally I prefer STL unless the home-grown alternatives makes a significant difference)

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@joyeecheung joyeecheung added commit-queue Add this label to land a pull request using GitHub Actions. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. labels Feb 8, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Feb 8, 2023
@nodejs-github-bot nodejs-github-bot merged commit a5ede9c into nodejs:main Feb 8, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in a5ede9c

MylesBorins pushed a commit that referenced this pull request Feb 18, 2023
Avoid using v8::Array::Set() which results in JS execution and is
thus slow. Prebuild the vector in C++ land and build the
JS array directly with that vector whereever possible.

PR-URL: #46447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Feb 19, 2023
danielleadams pushed a commit that referenced this pull request Apr 11, 2023
Avoid using v8::Array::Set() which results in JS execution and is
thus slow. Prebuild the vector in C++ land and build the
JS array directly with that vector whereever possible.

PR-URL: #46447
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
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++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants