src: use stack allocation for small string encoding#62431
Open
thisalihassan wants to merge 2 commits intonodejs:mainfrom
Open
src: use stack allocation for small string encoding#62431thisalihassan wants to merge 2 commits intonodejs:mainfrom
thisalihassan wants to merge 2 commits intonodejs:mainfrom
Conversation
e5fbafb to
43fd2f8
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62431 +/- ##
==========================================
+ Coverage 89.68% 89.71% +0.03%
==========================================
Files 676 692 +16
Lines 206738 213994 +7256
Branches 39594 41050 +1456
==========================================
+ Hits 185414 191994 +6580
- Misses 13467 14090 +623
- Partials 7857 7910 +53
🚀 New features to boost your workflow:
|
Flarna
reviewed
Mar 26, 2026
Use stack-allocated buffers in StringBytes::Encode() for small inputs instead of heap-allocating via UncheckedMalloc for every call. Refs: nodejs/performance#194
43fd2f8 to
73eb342
Compare
ronag
reviewed
Mar 29, 2026
ronag
reviewed
Mar 29, 2026
src/string_bytes.cc
Outdated
Comment on lines
+553
to
+560
| case BUFFER: { | ||
| auto maybe_buf = Buffer::Copy(isolate, buf, buflen); | ||
| Local<v8::Object> buf; | ||
| if (!maybe_buf.ToLocal(&buf)) { | ||
| isolate->ThrowException(node::ERR_MEMORY_ALLOCATION_FAILED(isolate)); | ||
| } | ||
| return buf; | ||
| } |
Member
There was a problem hiding this comment.
Seems like unnecessary whitespace change?
ronag
reviewed
Mar 29, 2026
ronag
approved these changes
Mar 29, 2026
Collaborator
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.
EncodeOneByteString/EncodeTwoByteStringhelper templates inStringBytes::Encode()that use a 512 byte (256-char for two-byte) stack buffer for small inputs, falling back to heap allocation +ExternStringfor larger ones.Refs: nodejs/performance#194