Skip to content

Commit 89758ce

Browse files
committed
fix: major performance issues with bytea performance brianc#2240
1 parent 316b119 commit 89758ce

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

packages/pg-protocol/src/parser.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ export class Parser {
150150
this.remainingBufferLength = 0
151151
this.remainingBufferOffset = 0
152152
} else {
153+
this.remainingBufferLength = fullLength - offset
153154
if (reuseRemainingBuffer) {
154155
// Adjust the cursors of remainingBuffer
155-
this.remainingBufferLength = combinedBufferLength - offset
156-
this.remainingBufferOffset += offset
156+
this.remainingBufferOffset = offset
157157
} else {
158-
// To avoid side effects, copy the remaining part of the new buffer to remainingBuffer
159-
this.remainingBuffer = combinedBuffer.slice(offset)
160-
this.remainingBufferLength = this.remainingBuffer.byteLength
158+
// To avoid side effects, copy the remaining part of the new buffer to remainingBuffer with extra space for next buffer
159+
this.remainingBuffer = Buffer.allocUnsafe(combinedBufferLength * 2)
160+
combinedBuffer.copy(this.remainingBuffer, 0, offset)
161161
this.remainingBufferOffset = 0
162162
}
163163
}

0 commit comments

Comments
 (0)