Skip to content

buffer: add isByteString - #66298

Open
jasnell wants to merge 1 commit into
nodejs:mainfrom
jasnell:jasnell/islatin1
Open

jasnell wants to merge 1 commit into
nodejs:mainfrom
jasnell:jasnell/islatin1

Conversation

@jasnell

@jasnell jasnell commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Implements a fast check to determine if a string is Latin1 a byte string.

Can be many times faster than the equivalent regex check.

input isByteString regex loop
short, one-byte 232M 122M 55M
short, two-byte 207M 130M 56M
short, invalid 106M 48M 53M
long, one-byte 221M 93M 230k
long, two-byte 6.7M 913k 186k
long, invalid 75M 914k 234k

(the larger perf gap there is with concatenated strings)

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/performance

@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 Sep 25, 2026
@aduh95

aduh95 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

I don't think isLatin1 is a good name, \u0100 can definitely be a 2-byte latin1 string

@jasnell

jasnell commented Sep 25, 2026

Copy link
Copy Markdown
Member Author

Yeah, I'm going to rename to isByteString ... it matches the webidl usage better.

@jasnell jasnell changed the title buffer: add isLatin1 buffer: add isByteString Sep 25, 2026
@jasnell jasnell added the semver-minor PRs that contain new features and should be released in the next minor version. label Sep 25, 2026
@jasnell
jasnell requested a review from aduh95 September 25, 2026 19:28
Comment thread src/node_buffer.cc Outdated
@jasnell jasnell added author ready PRs with CI started, the required approvals, and no outstanding review comments. request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. and removed request-ci Add this label to start a Jenkins CI on a PR. Only starts once the PR has an approving review. labels Sep 25, 2026
Implements a fast check to determine if a string is
a valid byte string (only chars <= 0xff).

Can be up to 58x faster than the equivalent regex check.

Signed-off-by: James M Snell <jasnell@gmail.com>
@nodejs-github-bot

nodejs-github-bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.37%. Comparing base (8bf65d4) to head (090b087).
⚠️ Report is 13 commits behind head on main.

Files with missing lines Patch % Lines
src/node_buffer.cc 76.92% 0 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66298      +/-   ##
==========================================
+ Coverage   90.36%   90.37%   +0.01%     
==========================================
  Files         790      790              
  Lines      273842   273876      +34     
  Branches    52386    52393       +7     
==========================================
+ Hits       247453   247523      +70     
+ Misses      16881    16852      -29     
+ Partials     9508     9501       -7     
Files with missing lines Coverage Δ
lib/buffer.js 99.74% <100.00%> (+<0.01%) ⬆️
src/node_buffer.cc 70.40% <76.92%> (+0.06%) ⬆️

... and 30 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.

@jasnell jasnell added the commit-queue PRs queued for automated landing through the Commit Queue. label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue PRs queued for automated landing through the Commit Queue. needs-ci PRs that need a full CI run. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants