Skip to content

Commit

Permalink
perf: cork socket for a micro task
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Apr 1, 2024
1 parent 2405c17 commit 89790d5
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class Sender {
}

this._socket = socket;
this._corked = false;
this._uncork = () => {
if (this._corked) {
this._corked = false;
this._socket.uncork();
}
}

Check failure on line 43 in lib/sender.js

View workflow job for this annotation

GitHub Actions / test (x64, 20, ubuntu-latest)

Insert `;`

this._firstFragment = true;
this._compress = false;
Expand Down Expand Up @@ -195,6 +202,10 @@ class Sender {
} else {
this.sendFrame(Sender.frame(buf, options), cb);
}

if (this._corked) {
this._socket.uncork();
}
}

/**
Expand Down Expand Up @@ -463,11 +474,15 @@ class Sender {
* @private
*/
sendFrame(list, cb) {
if (list.length === 2) {
if (!this._corked) {
this._corked = true;
this._socket.cork();
queueMicrotask(this._uncork);
}

if (list.length === 2) {
this._socket.write(list[0]);
this._socket.write(list[1], cb);
this._socket.uncork();
} else {
this._socket.write(list[0], cb);
}
Expand Down

0 comments on commit 89790d5

Please sign in to comment.