Skip to content

Commit

Permalink
Merge branch 'chkimes-alloc-unsafe'
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Aug 7, 2022
2 parents a98003e + 0aeb5f8 commit 3cace63
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,13 @@
# Change log for amqplib

## Changes in v0.10.2

git log v0.10.1..v0.10.2

- Use Buffer.allocUnsafe when sending messages to improve performance ([PR
695](https://github.com/amqp-node/amqplib/pull/695), thank you
@chkimes and @Uzlopak)

## Changes in v0.10.1

git log v0.10.0..v0.10.1
Expand Down
12 changes: 10 additions & 2 deletions lib/connection.js
Expand Up @@ -560,7 +560,11 @@ C.sendMessage = function(channel,
var allLen = methodHeaderLen + bodyLen;

if (allLen < SINGLE_CHUNK_THRESHOLD) {
var all = Buffer.alloc(allLen);
// 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.
// See https://github.com/amqp-node/amqplib/pull/695
var all = Buffer.allocUnsafe(allLen);
var offset = mframe.copy(all, 0);
offset += pframe.copy(all, offset);

Expand All @@ -570,7 +574,11 @@ C.sendMessage = function(channel,
}
else {
if (methodHeaderLen < SINGLE_CHUNK_THRESHOLD) {
var both = Buffer.alloc(methodHeaderLen);
// 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.
// See https://github.com/amqp-node/amqplib/pull/695
var both = Buffer.allocUnsafe(methodHeaderLen);
var offset = mframe.copy(both, 0);
pframe.copy(both, offset);
buffer.write(both);
Expand Down

0 comments on commit 3cace63

Please sign in to comment.