From 89758cee2f7306d1a3471fe9f64d86f5c25aa8b4 Mon Sep 17 00:00:00 2001 From: regevbr Date: Fri, 19 Jun 2020 03:39:06 +0300 Subject: [PATCH] fix: major performance issues with bytea performance #2240 --- packages/pg-protocol/src/parser.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/pg-protocol/src/parser.ts b/packages/pg-protocol/src/parser.ts index eabb1e3d7..56670fd75 100644 --- a/packages/pg-protocol/src/parser.ts +++ b/packages/pg-protocol/src/parser.ts @@ -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 } }