Skip to content

Commit c36c103

Browse files
committed
perf: create promisified socketWrite once per connection
1 parent 12bb88a commit c36c103

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/cmap/connection.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,8 @@ export class ModernConnection extends TypedEventEmitter<ConnectionEvents> {
819819
/** @event */
820820
static readonly UNPINNED = UNPINNED;
821821

822+
socketWrite: (buffer: Uint8Array, options: { signal: AbortSignal }) => Promise<void>;
823+
822824
constructor(stream: Stream, options: ConnectionOptions) {
823825
super();
824826

@@ -839,6 +841,11 @@ export class ModernConnection extends TypedEventEmitter<ConnectionEvents> {
839841
this.socket.on('error', this.onError.bind(this));
840842
this.socket.on('close', this.onClose.bind(this));
841843
this.socket.on('timeout', this.onTimeout.bind(this));
844+
845+
const socketWrite = promisify(this.socket.write.bind(this.socket));
846+
this.socketWrite = (buffer, options) => {
847+
return abortable(socketWrite(buffer), options);
848+
};
842849
}
843850

844851
async commandAsync(...args: Parameters<typeof this.command>) {
@@ -1256,9 +1263,7 @@ export async function writeCommand(
12561263

12571264
const buffer = Buffer.concat(await finalCommand.toBin());
12581265

1259-
const socketWriteFn = promisify(connection.socket.write.bind(connection.socket));
1260-
1261-
return abortable(socketWriteFn(buffer), options);
1266+
return connection.socketWrite(buffer, options);
12621267
}
12631268

12641269
/**

0 commit comments

Comments
 (0)