Skip to content

Commit fc5ca64

Browse files
committed
increase buffer default size & re-use buffer unless its gets larger than 8kb
1 parent 9a94fe9 commit fc5ca64

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/pg-protocol/src/buffer-writer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
//binary data writer tuned for encoding binary specific to the postgres binary protocol
22

3+
const MaxSize = 8192 //8kb
4+
35
export class Writer {
46
private buffer: Buffer
57
private offset: number = 5
68
private headerPosition: number = 0
7-
constructor(private size = 256) {
9+
constructor(private size = 512) {
810
this.buffer = Buffer.allocUnsafeSlow(size)
911
}
1012

@@ -91,7 +93,9 @@ export class Writer {
9193
let result = this.join(code)
9294
this.offset = 5
9395
this.headerPosition = 0
94-
this.buffer = Buffer.allocUnsafeSlow(this.size)
96+
if(this.buffer.length > MaxSize) {
97+
this.buffer = Buffer.allocUnsafeSlow(this.size)
98+
}
9599
return result
96100
}
97101
}

0 commit comments

Comments
 (0)