Skip to content

buffer: add fast api for isUtf8 and isAscii#64169

Merged
aduh95 merged 1 commit into
nodejs:mainfrom
gurgunday:feat/fast-api-isUtf8
Jul 6, 2026
Merged

buffer: add fast api for isUtf8 and isAscii#64169
aduh95 merged 1 commit into
nodejs:mainfrom
gurgunday:feat/fast-api-isUtf8

Conversation

@gurgunday

@gurgunday gurgunday commented Jun 27, 2026

Copy link
Copy Markdown
Member

I like V8's fast api constraints, so I'm in the process of checking if there are any easy wins that we haven't yet spotted

Benchmarks (3 run avg, M5 Pro):

   Benchmark               Baseline avg       New avg      Delta
  ━━━━━━━━━━━━━━━━━━━━━━  ━━━━━━━━━━━━━━  ━━━━━━━━━━━━  ━━━━━━━━━
   isAscii short             35,991,851    41,781,518    +16.09%
  ──────────────────────  ──────────────  ────────────  ─────────
   isAscii long              36,288,837    41,568,699    +14.55%
  ──────────────────────  ──────────────  ────────────  ─────────
   isUtf8 regular short      62,235,173    77,679,543    +24.82%
  ──────────────────────  ──────────────  ────────────  ─────────
   isUtf8 unicode short      54,727,530    67,448,276    +23.24%
  ──────────────────────  ──────────────  ────────────  ─────────
   isUtf8 regular long       21,936,234    23,323,246     +6.32%
  ──────────────────────  ──────────────  ────────────  ─────────
   isUtf8 unicode long        1,415,756     1,424,730     +0.63%

main:

./node benchmark/run.js --filter buffer-isutf8 --filter buffer-isascii buffers
buffers/buffer-isascii.js
buffers/buffer-isascii.js input="hello world" length="short" n=20000000: 36,815,465.272773266
buffers/buffer-isascii.js input="hello world" length="long" n=20000000: 36,183,770.13174511
buffers/buffer-isascii.js input="hello world" length="short" n=20000000: 36,618,408.943863295
buffers/buffer-isascii.js input="hello world" length="long" n=20000000: 35,746,630.542265736
buffers/buffer-isascii.js input="hello world" length="short" n=20000000: 36,457,306.78481872
buffers/buffer-isascii.js input="hello world" length="long" n=20000000: 36,401,698.177805796

buffers/buffer-isutf8.js
buffers/buffer-isutf8.js input="regular string" length="short" n=20000000: 62,364,681.698319875
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="short" n=20000000: 55,971,859.319343686
buffers/buffer-isutf8.js input="regular string" length="long" n=20000000: 22,072,747.830241162
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="long" n=20000000: 1,428,668.0720477349
buffers/buffer-isutf8.js input="regular string" length="short" n=20000000: 61,692,629.901998825
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="short" n=20000000: 55,769,467.558882594
buffers/buffer-isutf8.js input="regular string" length="long" n=20000000: 21,656,043.985478327
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="long" n=20000000: 1,411,666.258768642
buffers/buffer-isutf8.js input="regular string" length="short" n=20000000: 60,205,383.199316956
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="short" n=20000000: 54,345,813.96273032
buffers/buffer-isutf8.js input="regular string" length="long" n=20000000: 21,706,677.55977208
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="long" n=20000000: 1,417,130.332308522

branch:

./node benchmark/run.js --filter buffer-isutf8 --filter buffer-isascii buffers
buffers/buffer-isascii.js
buffers/buffer-isascii.js input="hello world" length="short" n=20000000: 42,042,571.75319534
buffers/buffer-isascii.js input="hello world" length="long" n=20000000: 41,993,784.33620464
buffers/buffer-isascii.js input="hello world" length="short" n=20000000: 41,651,213.719283365
buffers/buffer-isascii.js input="hello world" length="long" n=20000000: 41,547,685.95250074
buffers/buffer-isascii.js input="hello world" length="short" n=20000000: 41,650,769.262218766
buffers/buffer-isascii.js input="hello world" length="long" n=20000000: 41,164,626.14506766

buffers/buffer-isutf8.js
buffers/buffer-isutf8.js input="regular string" length="short" n=20000000: 78,129,501.6021431
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="short" n=20000000: 67,884,812.56127538
buffers/buffer-isutf8.js input="regular string" length="long" n=20000000: 23,347,893.348125998
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="long" n=20000000: 1,438,952.7056895334
buffers/buffer-isutf8.js input="regular string" length="short" n=20000000: 78,384,482.64411178
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="short" n=20000000: 68,071,405.20227206
buffers/buffer-isutf8.js input="regular string" length="long" n=20000000: 23,444,653.604879595
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="long" n=20000000: 1,421,397.567430693
buffers/buffer-isutf8.js input="regular string" length="short" n=20000000: 76,524,646.0555287
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="short" n=20000000: 66,388,609.0424605
buffers/buffer-isutf8.js input="regular string" length="long" n=20000000: 23,177,192.30868906
buffers/buffer-isutf8.js input="∀x∈ℝ: ⌈x⌉ = −⌊−x⌋" length="long" n=20000000: 1,413,840.9062698097

@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. labels Jun 27, 2026
@gurgunday gurgunday force-pushed the feat/fast-api-isUtf8 branch from 9929ec2 to 0217108 Compare June 27, 2026 11:40
@gurgunday gurgunday added the performance Issues and PRs related to the performance of Node.js. label Jun 27, 2026
@gurgunday

Copy link
Copy Markdown
Member Author

Cc @nodejs/performance

@gurgunday gurgunday added the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 29, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment thread src/node_buffer.cc Outdated
Comment thread src/node_buffer.cc Outdated

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@gurgunday

Copy link
Copy Markdown
Member Author

@addaleax PTAL, I did indeed find struct to be the cleaner here

@addaleax addaleax added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jun 30, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jun 30, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@addaleax addaleax added the request-ci Add this label to start a Jenkins CI on a PR. label Jul 2, 2026
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 2, 2026
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: nodejs#64169
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@aduh95 aduh95 force-pushed the feat/fast-api-isUtf8 branch from 7907c52 to c9f8721 Compare July 6, 2026 07:14
@aduh95

aduh95 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Landed in c9f8721

@aduh95 aduh95 merged commit c9f8721 into nodejs:main Jul 6, 2026
30 checks passed
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.04%. Comparing base (e6a8d06) to head (c9f8721).
⚠️ Report is 244 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64169      +/-   ##
==========================================
+ Coverage   92.01%   92.04%   +0.03%     
==========================================
  Files         379      381       +2     
  Lines      166972   169314    +2342     
  Branches    25554    25964     +410     
==========================================
+ Hits       153639   155852    +2213     
- Misses      13041    13173     +132     
+ Partials      292      289       -3     

see 105 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.

richardlau pushed a commit that referenced this pull request Jul 6, 2026
Signed-off-by: Gürgün Dayıoğlu <hey@gurgun.day>
PR-URL: #64169
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
@gurgunday gurgunday deleted the feat/fast-api-isUtf8 branch July 6, 2026 18:44
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. c++ Issues and PRs that require attention from people who are familiar with C++. 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