Skip to content

Commit 3b9f4ca

Browse files
committed
[perf] Enqueue send operations only when strictly necessary
1 parent 8ead18d commit 3b9f4ca

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/Sender.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Sender {
5555
buf.writeUInt16BE(code || 1000, 0, true);
5656
if (buf.length > 2) buf.write(data, 2);
5757

58-
if (this.perMessageDeflate) {
58+
if (this.deflating) {
5959
this.enqueue([this.doClose, buf, mask, cb]);
6060
} else {
6161
this.doClose(buf, mask, cb);
@@ -101,7 +101,7 @@ class Sender {
101101
}
102102
}
103103

104-
if (this.perMessageDeflate) {
104+
if (this.deflating) {
105105
this.enqueue([this.doPing, data, mask, readOnly]);
106106
} else {
107107
this.doPing(data, mask, readOnly);
@@ -147,7 +147,7 @@ class Sender {
147147
}
148148
}
149149

150-
if (this.perMessageDeflate) {
150+
if (this.deflating) {
151151
this.enqueue([this.doPong, data, mask, readOnly]);
152152
} else {
153153
this.doPong(data, mask, readOnly);
@@ -214,14 +214,20 @@ class Sender {
214214
if (options.fin) this.firstFragment = true;
215215

216216
if (this.perMessageDeflate) {
217-
this.enqueue([this.dispatch, data, {
217+
const opts = {
218218
compress: this.compress,
219219
mask: options.mask,
220220
fin: options.fin,
221221
readOnly,
222222
opcode,
223223
rsv1
224-
}, cb]);
224+
};
225+
226+
if (this.deflating) {
227+
this.enqueue([this.dispatch, data, opts, cb]);
228+
} else {
229+
this.dispatch(data, opts, cb);
230+
}
225231
} else {
226232
this.frameAndSend(data, {
227233
mask: options.mask,
@@ -366,7 +372,6 @@ class Sender {
366372
enqueue (params) {
367373
if (params[1]) this.bufferedBytes += params[1].length;
368374
this.queue.push(params);
369-
this.dequeue();
370375
}
371376
}
372377

0 commit comments

Comments
 (0)