Conversation
Unroll StringBytes hex decode so the common valid-input case processes four output bytes per iteration, while still stopping at the first invalid nibble. Official benchmark/buffers/buffer-hex-encode.js (Buffer.from hex): len=1024 is about 25% faster and len=64 is about 8% faster. Assisted-by: a closed-source coding agent Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
jasnell
approved these changes
Sep 21, 2026
Keep the invalid-nibble early exits on one line so format-cpp matches the project's clang-format. Assisted-by: a closed-source coding agent Signed-off-by: Yagiz Nizipli <yagiz@nizipli.com> Co-authored-by: Yagiz Nizipli <anonrig@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #66174 +/- ##
==========================================
+ Coverage 90.27% 90.29% +0.02%
==========================================
Files 790 790
Lines 271651 272080 +429
Branches 51842 51941 +99
==========================================
+ Hits 245228 245684 +456
+ Misses 16928 16899 -29
- Partials 9495 9497 +2
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Buffer.from(hex, 'hex')andbuf.write(hex, 'hex')both go throughStringBytes::Writeand the scalarnbytes::HexDecodeloop. Valid hex is the common case, so decode four output bytes per iteration and keep the existing “stop at the first invalid nibble” behavior (odd trailing nibble still ignored).This change was implemented with assistance from a closed-source coding agent. I verified the source, official
benchmark/buffers/buffer-hex-encode.jsresults, and the buffer hex tests listed below.Official benches
benchmark/buffers/buffer-hex-encode.js(Buffer.from(hex, 'hex')), three runs each, median rate:Tests
test-buffer-badhex,test-buffer-from,test-buffer-write,test-buffer-write-fast,test-buffer-tostring,test-buffer-tostring-range.