Skip to content

Commit 739ad0d

Browse files
committed
fix: reset batch size counter
When a batch of blocks was sent, the counter for the calculating the size wasn't reset. After the initial batch, every message was sent individually, which lead to a performance bottleneck. With this change receiving larger files (> 2MiB) is about 30% faster.
1 parent 51f5ce0 commit 739ad0d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/decision-engine/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class DecisionEngine {
5959
if (size >= MAX_MESSAGE_SIZE ||
6060
// need to ensure the last remaining items get sent
6161
outstanding === 0) {
62+
size = 0
6263
const nextBatch = batch.slice()
6364
batch = []
6465
this._sendSafeBlocks(peer, nextBatch, (err) => {

test/decision-engine/decision-engine.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,11 @@ describe('Engine', () => {
216216
})
217217

218218
const net = mockNetwork(5, (res) => {
219-
expect(res.messages).to.have.length(5)
219+
res.messages.forEach((message) => {
220+
// The batch size is big enough to hold two blocks, so every
221+
// message should contain two blocks
222+
expect(message[1].blocks.size).to.eql(2)
223+
})
220224
done()
221225
})
222226

0 commit comments

Comments
 (0)