Skip to content

Conversation

@anonrig
Copy link
Member

@anonrig anonrig commented Nov 24, 2025

Port of cloudflare/workerd#5448

Co-authored-by: Erik Corry (@erikcorry)
Co-authored-by: Daniel Lemire (@lemire)

This path can be optimized even more when Chromium PR (for updating simdutf https://chromium-review.googlesource.com/c/chromium/src/+/7199521) lands and v8 updates and includes it in a new release, and node.js updates v8 version...


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

confidence improvement accuracy (*)     (**)    (***)
15:32:37  util/text-encoder.js op='encode' type='ascii' n=1000000 len=1024                              -0.31 %       ±1.32%   ±1.75%   ±2.28%
15:32:37  util/text-encoder.js op='encode' type='ascii' n=1000000 len=256                                0.22 %       ±0.71%   ±0.94%   ±1.23%
15:32:37  util/text-encoder.js op='encode' type='ascii' n=1000000 len=32                         **     -1.24 %       ±0.84%   ±1.12%   ±1.46%
15:32:37  util/text-encoder.js op='encode' type='ascii' n=1000000 len=8192                      ***     -0.50 %       ±0.09%   ±0.12%   ±0.15%
15:32:37  util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=1024            ***      1.18 %       ±0.62%   ±0.82%   ±1.07%
15:32:37  util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=256                     -0.10 %       ±0.74%   ±0.98%   ±1.28%
15:32:37  util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=32               **     -1.24 %       ±0.91%   ±1.21%   ±1.57%
15:32:37  util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=8192                     0.01 %       ±0.06%   ±0.08%   ±0.11%
15:32:37  util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=1024            ***     -0.85 %       ±0.21%   ±0.29%   ±0.37%
15:32:37  util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=256             ***     -1.18 %       ±0.66%   ±0.87%   ±1.14%
15:32:37  util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=32                       0.43 %       ±1.01%   ±1.35%   ±1.76%
15:32:37  util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=8192            ***     -0.25 %       ±0.04%   ±0.05%   ±0.07%
15:32:37  util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=1024                  ***    654.06 %      ±14.64%  ±19.73%  ±26.20%
15:32:37  util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=256                   ***    197.67 %       ±7.34%   ±9.89%  ±13.13%
15:32:37  util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=32                    ***    -22.79 %       ±2.61%   ±3.48%   ±4.56%
15:32:37  util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=8192                  ***   1829.66 %      ±78.90% ±106.33% ±141.17%
15:32:37  util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=1024        ***    163.76 %      ±11.41%  ±15.38%  ±20.42%
15:32:37  util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=256         ***     32.93 %       ±1.07%   ±1.44%   ±1.89%
15:32:37  util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=32           **     -4.92 %       ±3.31%   ±4.41%   ±5.75%
15:32:37  util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=8192        ***    303.17 %       ±0.97%   ±1.30%   ±1.73%
15:32:37  util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=1024        ***    108.52 %       ±3.18%   ±4.28%   ±5.69%
15:32:37  util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=256         ***     13.48 %       ±0.82%   ±1.09%   ±1.43%
15:32:37  util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=32            *     -2.42 %       ±2.22%   ±2.95%   ±3.84%
15:32:37  util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=8192        ***    180.96 %       ±0.20%   ±0.27%   ±0.36%

@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 Nov 24, 2025
@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch from 518b877 to d6ac366 Compare November 24, 2025 19:54
@anonrig anonrig requested a review from guybedford November 24, 2025 19:54
@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch 2 times, most recently from d47585e to 699bf56 Compare November 24, 2025 20:00
@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch 2 times, most recently from 495c148 to 52dc8a7 Compare November 24, 2025 20:09
@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch 10 times, most recently from 028c409 to 6c5656f Compare November 24, 2025 21:26
Co-authored-by: Erik Corry <[email protected]>
Co-authored-by: Daniel Lemire <[email protected]>
@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch from 6c5656f to f993411 Compare November 24, 2025 21:38
@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch from 9f9733a to 66bc586 Compare November 24, 2025 22:33
@anonrig
Copy link
Member Author

anonrig commented Nov 26, 2025

@RafaelGSS please take a look

@RafaelGSS RafaelGSS added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci Add this label to start a Jenkins CI on a PR. labels Nov 26, 2025
@RafaelGSS RafaelGSS added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 26, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 26, 2025
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. label Nov 26, 2025

size_t read = 0;
size_t written = 0;
v8::String::ValueView view(isolate, source);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
v8::String::ValueView view(isolate, source);
// Note: Take care not to perform any action in v8 that would
// trigger GC as it could cause the view to become invalid.
v8::String::ValueView view(isolate, source);

simdutf::result result =
simdutf::validate_ascii_with_errors(data, length_that_fits);
written = read = result.count;
memcpy(write_result, data, read);
Copy link
Member

Choose a reason for hiding this comment

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

A DCHECK for bounds checking would be nice here.

@anonrig anonrig force-pushed the yagiz/improve-textencoder-encodeinto branch from bdd8c13 to 730da98 Compare November 30, 2025 02:55
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Nov 30, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Nov 30, 2025
@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 Dec 1, 2025
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Dec 1, 2025
@nodejs-github-bot nodejs-github-bot merged commit b1e941e into nodejs:main Dec 1, 2025
66 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in b1e941e

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. needs-ci PRs that need a full CI run. performance Issues and PRs related to the performance of Node.js.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants