Skip to content

Commit

Permalink
fix: major performance issues with bytea performance brianc#2240
Browse files Browse the repository at this point in the history
  • Loading branch information
regevbr committed Jun 19, 2020
1 parent 316b119 commit 89758ce
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/pg-protocol/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ export class Parser {
this.remainingBufferLength = 0
this.remainingBufferOffset = 0
} else {
this.remainingBufferLength = fullLength - offset
if (reuseRemainingBuffer) {
// Adjust the cursors of remainingBuffer
this.remainingBufferLength = combinedBufferLength - offset
this.remainingBufferOffset += offset
this.remainingBufferOffset = offset
} else {
// To avoid side effects, copy the remaining part of the new buffer to remainingBuffer
this.remainingBuffer = combinedBuffer.slice(offset)
this.remainingBufferLength = this.remainingBuffer.byteLength
// To avoid side effects, copy the remaining part of the new buffer to remainingBuffer with extra space for next buffer
this.remainingBuffer = Buffer.allocUnsafe(combinedBufferLength * 2)
combinedBuffer.copy(this.remainingBuffer, 0, offset)
this.remainingBufferOffset = 0
}
}
Expand Down

0 comments on commit 89758ce

Please sign in to comment.