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 f7879c9
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 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 @@ -463,11 +470,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 f7879c9

Please sign in to comment.