Skip to content

src: improve TextEncoder encodeInto performance #58080

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

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

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Apr 29, 2025

Improves the performance of TextEncoder.encodeInto method

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

It seems none of the benchmarks are triggering the fast path

14:13:35                                                                                confidence improvement accuracy (*)   (**)  (***)
14:13:35 util/text-encoder.js op='encode' type='ascii' n=1000000 len=1024                              -0.36 %       ±1.01% ±1.35% ±1.76%
14:13:35 util/text-encoder.js op='encode' type='ascii' n=1000000 len=256                                0.04 %       ±1.82% ±2.43% ±3.17%
14:13:35 util/text-encoder.js op='encode' type='ascii' n=1000000 len=32                                -0.33 %       ±0.87% ±1.16% ±1.52%
14:13:35 util/text-encoder.js op='encode' type='ascii' n=1000000 len=8192                               0.01 %       ±0.34% ±0.45% ±0.58%
14:13:35 util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=1024                    -0.56 %       ±0.62% ±0.82% ±1.07%
14:13:35 util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=256                     -0.17 %       ±0.85% ±1.13% ±1.48%
14:13:35 util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=32                       0.84 %       ±1.03% ±1.37% ±1.78%
14:13:35 util/text-encoder.js op='encode' type='one-byte-string' n=1000000 len=8192              *      0.07 %       ±0.06% ±0.07% ±0.10%
14:13:35 util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=1024            ***     -2.76 %       ±0.49% ±0.65% ±0.85%
14:13:35 util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=256                      0.58 %       ±0.71% ±0.94% ±1.22%
14:13:35 util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=32                      -0.39 %       ±0.78% ±1.03% ±1.35%
14:13:35 util/text-encoder.js op='encode' type='two-byte-string' n=1000000 len=8192            ***     -4.32 %       ±0.12% ±0.16% ±0.21%
14:13:35 util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=1024                  ***     -4.49 %       ±0.51% ±0.68% ±0.88%
14:13:35 util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=256                   ***     -4.55 %       ±0.80% ±1.08% ±1.41%
14:13:35 util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=32                    ***     -6.35 %       ±1.21% ±1.61% ±2.09%
14:13:35 util/text-encoder.js op='encodeInto' type='ascii' n=1000000 len=8192                   **     -1.86 %       ±1.27% ±1.69% ±2.20%
14:13:35 util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=1024        ***     -0.51 %       ±0.26% ±0.35% ±0.45%
14:13:35 util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=256         ***     -1.14 %       ±0.24% ±0.32% ±0.42%
14:13:35 util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=32                  -0.71 %       ±0.99% ±1.31% ±1.71%
14:13:35 util/text-encoder.js op='encodeInto' type='one-byte-string' n=1000000 len=8192        ***     -0.35 %       ±0.04% ±0.05% ±0.07%
14:13:35 util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=1024                -0.32 %       ±0.34% ±0.45% ±0.58%
14:13:35 util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=256                 -0.22 %       ±0.24% ±0.32% ±0.41%
14:13:35 util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=32          ***     -3.57 %       ±1.10% ±1.47% ±1.92%
14:13:35 util/text-encoder.js op='encodeInto' type='two-byte-string' n=1000000 len=8192        ***      0.92 %       ±0.20% ±0.26% ±0.34%
@anonrig anonrig requested review from lemire, jasnell and ronag April 29, 2025 17:42
@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 Apr 29, 2025
Copy link

codecov bot commented Apr 29, 2025

Codecov Report

Attention: Patch coverage is 17.39130% with 19 lines in your changes missing coverage. Please review.

Project coverage is 90.21%. Comparing base (a36981a) to head (635769a).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/encoding_binding.cc 17.39% 19 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58080      +/-   ##
==========================================
- Coverage   90.21%   90.21%   -0.01%     
==========================================
  Files         630      630              
  Lines      186391   186420      +29     
  Branches    36608    36611       +3     
==========================================
+ Hits       168161   168170       +9     
- Misses      11052    11070      +18     
- Partials     7178     7180       +2     
Files with missing lines Coverage Δ
src/encoding_binding.h 100.00% <ø> (ø)
src/node_external_reference.h 100.00% <ø> (ø)
src/encoding_binding.cc 72.36% <17.39%> (-7.30%) ⬇️

... and 31 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
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++. needs-ci PRs that need a full CI run.
3 participants