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 9ce175d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ class Sender {
}

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

Check failure on line 42 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 +201,10 @@ class Sender {
} else {
this.sendFrame(Sender.frame(buf, options), cb);
}

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

/**
Expand Down Expand Up @@ -463,11 +473,14 @@ class Sender {
* @private
*/
sendFrame(list, cb) {
if (list.length === 2) {
if (!this._corked) {
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 9ce175d

Please sign in to comment.