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

buffer: improve atob performance #52381

Closed
wants to merge 2 commits into from
Closed

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Apr 5, 2024

The code is 99% written by @lemire, I just glued them all together.

This pull-request introduces a much faster atob implementation, and solves solves some security aspects of the previous implementation. Usage of atob is still discouraged.

Refs: #51670

Benchmarks

                                          confidence improvement accuracy (*)    (**)   (***)
buffers/buffer-atob.js n=1000000 size=16         ***    457.77 %       ±3.28%  ±4.42%  ±5.86%
buffers/buffer-atob.js n=1000000 size=256        ***   2505.57 %      ±15.69% ±21.14% ±28.07%
buffers/buffer-atob.js n=1000000 size=64         ***   1213.33 %       ±3.98%  ±5.36%  ±7.11%

Be aware that when doing many comparisons the risk of a false-positive result increases.
In this case, there are 3 comparisons, you can thus expect the following amount of false-positive results:
  0.15 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.03 false positives, when considering a   1% risk acceptance (**, ***),
  0.00 false positives, when considering a 0.1% risk acceptance (***)

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/security-wg

@nodejs-github-bot nodejs-github-bot added lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Apr 5, 2024
@anonrig anonrig added buffer Issues and PRs related to the buffer subsystem. notable-change PRs with changes that should be highlighted in changelogs. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. labels Apr 5, 2024
Copy link
Contributor

github-actions bot commented Apr 5, 2024

The notable-change PRs with changes that should be highlighted in changelogs. label has been added by @anonrig.

Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section.

@Jarred-Sumner
Copy link

nice

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 5, 2024
Copy link
Member

@H4ad H4ad left a comment

Choose a reason for hiding this comment

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

Awesome 🚀

result.csv Outdated Show resolved Hide resolved
buffer.csv Outdated Show resolved Hide resolved
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 5, 2024
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Apr 5, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Apr 5, 2024
@nodejs-github-bot
Copy link
Collaborator

@MattIPv4
Copy link
Member

MattIPv4 commented Apr 5, 2024

I notice that a comment referencing #38433 (comment) was removed.

Making these functions faster tells people that it’s okay to use them. It’s not, therefore let’s not worry about their performance at all.

Has the position changed, that these should now be optimized?

@lemire
Copy link
Member

lemire commented Apr 5, 2024

@MattIPv4 I won't comment directly on your objection, but I'd like to point out that the same approach can be used, and will be used, to accelerate the recommended Buffer functions.

There is, however, a significant difference between atob and the recommended Buffer functions: atob validates the input. The recommended Buffer functions offer no validation and are underspecified.

@MattIPv4
Copy link
Member

MattIPv4 commented Apr 5, 2024

To be clear, I don't object, I'm all for performance increase! Just wanted to check the overall position of Node was that this should be optimized now, when before it seems it wasn't

@anonrig
Copy link
Member Author

anonrig commented Apr 5, 2024

To be clear, I don't object, I'm all for performance increase! Just wanted to check the overall position of Node was that this should be optimized now, when before it seems it wasn't

atob is deprecated and not recommended to be used (don't know why, but the reasoning doesn't matter for the purpose of this PR).

@richardlau
Copy link
Member

I notice that a comment referencing #38433 (comment) was removed.

Making these functions faster tells people that it’s okay to use them. It’s not, therefore let’s not worry about their performance at all.

Has the position changed, that these should now be optimized?

It was discussed in a TSC meeting -- nodejs/TSC#1503, recording: https://www.youtube.com/watch?v=B5phSZ7jjwk. I can't seem to find the meeting minutes in the TSC repo -- the linked PR in the issue is for the following week's meeting.

My recollection is there was consensus in the meeting that #51670 could land (not sure why it hasn't) on the basis that it was purely JS and fairly minimal. Use of atob is still discouraged.

@richardlau
Copy link
Member

This pull-request introduces blazing fast atob implementation which is more secure and faster.

Can you expand on/explain "more secure"?

@lemire
Copy link
Member

lemire commented Apr 6, 2024

@richardlau From the linked issue:

This is a DoS vector to the unaware user and irresponsible IMO.

@lemire
Copy link
Member

lemire commented Apr 6, 2024

(Note that the above comment is quote from the linked issue, not something @anonrig wrote.)

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, but not much useful in practice.

@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 8, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 8, 2024
@nodejs-github-bot
Copy link
Collaborator

Commit Queue failed
- Loading data for nodejs/node/pull/52381
✔  Done loading data for nodejs/node/pull/52381
----------------------------------- PR info ------------------------------------
Title      buffer: improve `atob` performance (#52381)
Author     Yagiz Nizipli  (@anonrig)
Branch     anonrig:deps/simdutf -> nodejs:main
Labels     buffer, lib / src, author ready, needs-ci, commit-queue-rebase
Commits    2
 - deps: update simdutf to 5.2.3
 - buffer: use simdutf for `atob` implementation
Committers 1
 - Yagiz Nizipli 
PR-URL: https://github.com/nodejs/node/pull/52381
Fixes: https://github.com/nodejs/node/pull/51670
Reviewed-By: Daniel Lemire 
Reviewed-By: Vinícius Lourenço Claro Cardoso 
Reviewed-By: Matteo Collina 
Reviewed-By: Robert Nagy 
Reviewed-By: Benjamin Gruenbaum 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/52381
Fixes: https://github.com/nodejs/node/pull/51670
Reviewed-By: Daniel Lemire 
Reviewed-By: Vinícius Lourenço Claro Cardoso 
Reviewed-By: Matteo Collina 
Reviewed-By: Robert Nagy 
Reviewed-By: Benjamin Gruenbaum 
--------------------------------------------------------------------------------
   ℹ  This PR was created on Fri, 05 Apr 2024 21:43:53 GMT
   ✔  Approvals: 5
   ✔  - Daniel Lemire (@lemire): https://github.com/nodejs/node/pull/52381#pullrequestreview-1984251249
   ✔  - Vinícius Lourenço Claro Cardoso (@H4ad): https://github.com/nodejs/node/pull/52381#pullrequestreview-1984254833
   ✔  - Matteo Collina (@mcollina) (TSC): https://github.com/nodejs/node/pull/52381#pullrequestreview-1984441422
   ✔  - Robert Nagy (@ronag) (TSC): https://github.com/nodejs/node/pull/52381#pullrequestreview-1984457362
   ✔  - Benjamin Gruenbaum (@benjamingr) (TSC): https://github.com/nodejs/node/pull/52381#pullrequestreview-1984572522
   ✔  Last GitHub CI successful
   ℹ  Last Full PR CI on 2024-04-08T01:47:22Z: https://ci.nodejs.org/job/node-test-pull-request/58199/
- Querying data for job/node-test-pull-request/58199/
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  No git cherry-pick in progress
   ✔  No git am in progress
   ✔  No git rebase in progress
--------------------------------------------------------------------------------
- Bringing origin/main up to date...
From https://github.com/nodejs/node
 * branch                  main       -> FETCH_HEAD
✔  origin/main is now up-to-date
- Downloading patch for 52381
From https://github.com/nodejs/node
 * branch                  refs/pull/52381/merge -> FETCH_HEAD
✔  Fetched commits as 128c60d90609..a790e5857196
--------------------------------------------------------------------------------
[main 1b747b2803] deps: update simdutf to 5.2.3
 Author: Yagiz Nizipli 
 Date: Thu Apr 4 17:53:41 2024 -0400
 2 files changed, 2204 insertions(+), 959 deletions(-)
Auto-merging src/node_buffer.cc
[main 225c7e7795] buffer: use simdutf for `atob` implementation
 Author: Yagiz Nizipli 
 Date: Thu Apr 4 18:03:17 2024 -0400
 3 files changed, 93 insertions(+), 73 deletions(-)
 create mode 100644 benchmark/buffers/buffer-atob.js
   ✔  Patches applied
There are 2 commits in the PR. Attempting autorebase.
Rebasing (2/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
deps: update simdutf to 5.2.3

PR-URL: #52381
Fixes: #51670
Reviewed-By: Daniel Lemire [email protected]
Reviewed-By: Vinícius Lourenço Claro Cardoso [email protected]
Reviewed-By: Matteo Collina [email protected]
Reviewed-By: Robert Nagy [email protected]
Reviewed-By: Benjamin Gruenbaum [email protected]

[detached HEAD ce2fd04108] deps: update simdutf to 5.2.3
Author: Yagiz Nizipli [email protected]
Date: Thu Apr 4 17:53:41 2024 -0400
2 files changed, 2204 insertions(+), 959 deletions(-)
Rebasing (3/4)
Rebasing (4/4)

Executing: git node land --amend --yes
--------------------------------- New Message ----------------------------------
buffer: use simdutf for atob implementation

Co-authored-by: Daniel Lemire [email protected]
PR-URL: #52381
Fixes: #51670
Reviewed-By: Daniel Lemire [email protected]
Reviewed-By: Vinícius Lourenço Claro Cardoso [email protected]
Reviewed-By: Matteo Collina [email protected]
Reviewed-By: Robert Nagy [email protected]
Reviewed-By: Benjamin Gruenbaum [email protected]

[detached HEAD d8a53adcd5] buffer: use simdutf for atob implementation
Author: Yagiz Nizipli [email protected]
Date: Thu Apr 4 18:03:17 2024 -0400
3 files changed, 93 insertions(+), 73 deletions(-)
create mode 100644 benchmark/buffers/buffer-atob.js

Successfully rebased and updated refs/heads/main.

✖ ce2fd04108b1993cda354c46404010dea3e5decc
✔ 0:0 no Co-authored-by metadata co-authored-by-is-trailer
✖ 2:7 Pull request URL must reference a comment or discussion. fixes-url
✔ 0:0 blank line after title line-after-title
✔ 0:0 line-lengths are valid line-length
✔ 0:0 metadata is at end of message metadata-end
✔ 1:8 PR-URL is valid. pr-url
✔ 0:0 reviewers are valid reviewers
✔ 0:0 valid subsystems subsystem
✔ 0:0 Title is formatted correctly. title-format
✔ 0:0 Title is <= 50 columns. title-length
✖ d8a53adcd5d3d6c299c9f95872c827e6c3d81363
✔ 0:0 Co-authored-by is a trailer co-authored-by-is-trailer
✖ 3:7 Pull request URL must reference a comment or discussion. fixes-url
✔ 0:0 blank line after title line-after-title
✔ 0:0 line-lengths are valid line-length
✔ 0:0 metadata is at end of message metadata-end
✔ 2:8 PR-URL is valid. pr-url
✔ 0:0 reviewers are valid reviewers
✔ 0:0 valid subsystems subsystem
✔ 0:0 Title is formatted correctly. title-format
✔ 0:0 Title is <= 50 columns. title-length
ℹ Please fix the commit message and try again.
Please manually ammend the commit message, by running
git commit --amend
Once commit message is fixed, finish the landing command running
git node land --continue

https://github.com/nodejs/node/actions/runs/8593473401

@nodejs-github-bot nodejs-github-bot added the commit-queue-failed An error occurred while landing this pull request using GitHub Actions. label Apr 8, 2024
Copy link
Contributor

@Uzlopak Uzlopak left a comment

Choose a reason for hiding this comment

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

LGTM

@anonrig anonrig added commit-queue Add this label to land a pull request using GitHub Actions. and removed commit-queue-failed An error occurred while landing this pull request using GitHub Actions. labels Apr 8, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Apr 8, 2024
@nodejs-github-bot
Copy link
Collaborator

Landed in 08609b5...6f504b7

nodejs-github-bot pushed a commit that referenced this pull request Apr 8, 2024
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
nodejs-github-bot pushed a commit that referenced this pull request Apr 8, 2024
Co-authored-by: Daniel Lemire <[email protected]>
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
richardlau pushed a commit that referenced this pull request Apr 26, 2024
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
marco-ippolito pushed a commit that referenced this pull request May 2, 2024
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
marco-ippolito pushed a commit that referenced this pull request May 2, 2024
Co-authored-by: Daniel Lemire <[email protected]>
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
marco-ippolito pushed a commit that referenced this pull request May 3, 2024
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
marco-ippolito pushed a commit that referenced this pull request May 3, 2024
Co-authored-by: Daniel Lemire <[email protected]>
PR-URL: #52381
Refs: #51670
Reviewed-By: Daniel Lemire <[email protected]>
Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Robert Nagy <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
@richardlau richardlau mentioned this pull request May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. buffer Issues and PRs related to the buffer subsystem. commit-queue-rebase Add this label to allow the Commit Queue to land a PR in several commits. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.