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

src: improve utf8 string generation performance #54873

Merged
merged 4 commits into from
Sep 17, 2024

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Sep 10, 2024

This speeds up Utf8Value across all Node.js codebase. We add a fast path for one byte strings and use the new V8 API (String::ValueView) with simdutf for non-byte strings. Once simdutf supports null termination and invalid character replacement, we can improve the performance more.

cc @nodejs/performance @lemire

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/1637/

@anonrig anonrig added dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. labels Sep 10, 2024
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Sep 10, 2024
@anonrig anonrig added the performance Issues and PRs related to the performance of Node.js. label Sep 10, 2024
@anonrig anonrig requested a review from lemire September 10, 2024 14:35
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Sep 10, 2024
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Sep 10, 2024
Copy link
Contributor

Failed to start CI
- Validating Jenkins credentials
✔  Jenkins credentials valid
- Starting PR CI job
✘  Failed to start PR CI: 400 Bad Request
https://github.com/nodejs/node/actions/runs/10795045779

@jasnell
Copy link
Member

jasnell commented Sep 10, 2024

CI failures look relevant to this change.

@lemire
Copy link
Member

lemire commented Sep 10, 2024

CI failures look relevant to this change.

Oh no.

src/util.cc Show resolved Hide resolved
src/util.cc Outdated Show resolved Hide resolved
src/util.cc Outdated Show resolved Hide resolved
src/util.cc Outdated Show resolved Hide resolved
@RafaelGSS
Copy link
Member

Since the PR is claiming for performance, we should have benchmarks.

Copy link

codecov bot commented Sep 10, 2024

Codecov Report

Attention: Patch coverage is 84.61538% with 4 lines in your changes missing coverage. Please review.

Project coverage is 88.08%. Comparing base (9db6327) to head (4b28cf1).
Report is 271 commits behind head on main.

Files with missing lines Patch % Lines
src/string_bytes.cc 66.66% 2 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #54873      +/-   ##
==========================================
+ Coverage   88.05%   88.08%   +0.02%     
==========================================
  Files         651      651              
  Lines      183405   183551     +146     
  Branches    35822    35867      +45     
==========================================
+ Hits       161499   161676     +177     
+ Misses      15159    15133      -26     
+ Partials     6747     6742       -5     
Files with missing lines Coverage Δ
src/util.cc 87.34% <100.00%> (+0.32%) ⬆️
src/string_bytes.cc 68.43% <66.66%> (+4.48%) ⬆️

... and 50 files with indirect coverage changes

@anonrig
Copy link
Member Author

anonrig commented Sep 10, 2024

Since the PR is claiming for performance, we should have benchmarks.

I don't know how to have an isolated benchmark for this. Any recommendations @RafaelGSS?

@RafaelGSS
Copy link
Member

I don't know how to have an isolated benchmark for this.

So, how do you know this PR is improving performance then?

Any recommendations?

I suspect if you measure any public API that makes use of this new branch behind the scenes you should get a feasible result

@anonrig anonrig force-pushed the speed-up-utf8value branch 4 times, most recently from 7556dc8 to 70263e8 Compare September 11, 2024 15:22
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.

RSLGTM

@RafaelGSS
Copy link
Member

@RafaelGSS I didn't forgot your comment. I've already attached a benchmark ci run to the description. it doesn't effect all paths only latin1 paths and it shows up to 7-8% improvement.

I might be missing something, but the benchmark result doesn't show any improvement if you consider the standard deviation. It also shows some regressions though.

@lemire
Copy link
Member

lemire commented Sep 12, 2024

@anonrig @RafaelGSS There is no harm at all in taking extra time.

Views have tremendous potential to speed up Node will lowering its memory usage. But as with all new things, it will take time to understand how to use it best in the Node code base.

@lemire
Copy link
Member

lemire commented Sep 12, 2024

@anonrig @RafaelGSS (By extra time, I meant days, not months.)

@anonrig

This comment was marked as outdated.

Co-authored-by: Daniel Lemire <daniel@lemire.me>
@anonrig
Copy link
Member Author

anonrig commented Sep 12, 2024

ronag
ronag previously requested changes Sep 12, 2024
src/util.cc Outdated Show resolved Hide resolved
Co-authored-by: Robert Nagy <ronagy@icloud.com>
@anonrig anonrig requested a review from ronag September 12, 2024 15:57
src/util.cc Outdated Show resolved Hide resolved
Co-authored-by: Robert Nagy <ronagy@icloud.com>
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig
Copy link
Member Author

anonrig commented Sep 15, 2024

@ronag Can you review?

@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig dismissed ronag’s stale review September 17, 2024 00:14

Addressed the recommendation. Dismissing.

@anonrig anonrig 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 Sep 17, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Sep 17, 2024
@nodejs-github-bot nodejs-github-bot merged commit 8191e1f into nodejs:main Sep 17, 2024
56 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 8191e1f

@targos targos added the dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. label Oct 4, 2024
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. dont-land-on-v18.x PRs that should not land on the v18.x-staging branch and should not be released in v18.x. dont-land-on-v20.x PRs that should not land on the v20.x-staging branch and should not be released in v20.x. dont-land-on-v22.x PRs that should not land on the v22.x-staging branch and should not be released in v22.x. performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants