Skip to content

Commit

Permalink
Update connection.js
Browse files Browse the repository at this point in the history
  • Loading branch information
chkimes authored Aug 4, 2022
1 parent 2f952fe commit 9da3c9b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,9 @@ C.sendMessage = function(channel,
var allLen = methodHeaderLen + bodyLen;

if (allLen < SINGLE_CHUNK_THRESHOLD) {
// Use `allocUnsafe` to avoid excessive allocations and CPU usage
// from zeroing. The returned Buffer is not zeroed and so must be
// completely filled to be used safely.
var all = Buffer.allocUnsafe(allLen);
var offset = mframe.copy(all, 0);
offset += pframe.copy(all, offset);
Expand All @@ -570,6 +573,9 @@ C.sendMessage = function(channel,
}
else {
if (methodHeaderLen < SINGLE_CHUNK_THRESHOLD) {
// Use `allocUnsafe` to avoid excessive allocations and CPU usage
// from zeroing. The returned Buffer is not zeroed and so must be
// completely filled to be used safely.
var both = Buffer.allocUnsafe(methodHeaderLen);
var offset = mframe.copy(both, 0);
pframe.copy(both, offset);
Expand Down

0 comments on commit 9da3c9b

Please sign in to comment.