Skip to content

lib: use on-heap Uint8Array in TextEncoder.encode up to 64 bytes - #67873

Open
mertcanaltin wants to merge 1 commit into
nodejs:mainfrom
mertcanaltin:textencoder-encode-64
Open

mertcanaltin wants to merge 1 commit into
nodejs:mainfrom
mertcanaltin:textencoder-encode-64

Conversation

@mertcanaltin

Copy link
Copy Markdown
Member

TextEncoder.encode now uses an on-heap Uint8Array for 33–64 character strings.

node benchmark/compare.js --old ./node-main --new ./node-pr --runs 30 --filter text-encoder --set op=encode util
                                             confidence   improvement   accuracy (*)    (**)   (***)
op='encode' type='one-byte-string' len=16                   +1.35 %   ±2.18%  ±2.90%  ±3.78%
op='encode' type='two-byte-string' len=16                   -0.85 %   ±1.83%  ±2.44%  ±3.20%
op='encode' type='ascii' len=16                             +1.17 %   ±1.97%  ±2.62%  ±3.41%
op='encode' type='one-byte-string' len=32     *             +1.79 %   ±1.56%  ±2.09%  ±2.72%
op='encode' type='two-byte-string' len=32                   +1.38 %   ±2.81%  ±3.74%  ±4.87%
op='encode' type='ascii' len=32                             +0.45 %   ±1.87%  ±2.49%  ±3.25%
op='encode' type='one-byte-string' len=33                   -1.38 %   ±3.06%  ±4.07%  ±5.30%
op='encode' type='two-byte-string' len=33     *             -3.53 %   ±3.01%  ±4.01%  ±5.22%
op='encode' type='ascii' len=33             ***           +192.05 %   ±4.42%  ±5.89%  ±7.68%
op='encode' type='one-byte-string' len=48                   -2.83 %   ±3.47%  ±4.62%  ±6.03%
op='encode' type='two-byte-string' len=48                   -0.97 %   ±3.42%  ±4.55%  ±5.93%
op='encode' type='ascii' len=48             ***           +169.62 %   ±5.18%  ±6.89%  ±8.97%
op='encode' type='one-byte-string' len=64                   -0.70 %   ±4.14%  ±5.51%  ±7.18%
op='encode' type='two-byte-string' len=64                   +1.33 %   ±3.08%  ±4.10%  ±5.34%
op='encode' type='ascii' len=64             ***           +158.15 %   ±3.97%  ±5.28%  ±6.88%
op='encode' type='one-byte-string' len=65                   +1.35 %   ±3.99%  ±5.32%  ±6.92%
op='encode' type='two-byte-string' len=65                   +0.62 %   ±4.18%  ±5.58%  ±7.30%
op='encode' type='ascii' len=65                             +0.24 %   ±4.83%  ±6.45%  ±8.42%
op='encode' type='one-byte-string' len=256                  +1.84 %   ±3.49%  ±4.64%  ±6.04%
op='encode' type='two-byte-string' len=256                  -2.09 %   ±2.69%  ±3.58%  ±4.66%
op='encode' type='ascii' len=256                            -1.62 %   ±3.92%  ±5.23%  ±6.81%

After Holm-Bonferroni correction across 21 comparisons, 3 remain significant at 5%.

Assisted-by: Claude Opus 5.5
Signed-off-by: Mert Can Altin <mertgold60@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run. typings Issues and PRs related to internal TypeScript declarations. labels Nov 29, 2026
@mertcanaltin
mertcanaltin marked this pull request as ready for review November 29, 2026 18:59
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++. encoding Issues and PRs related to the TextEncoder and TextDecoder APIs. needs-ci PRs that need a full CI run. typings Issues and PRs related to internal TypeScript declarations.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants