-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http: merge chunks during chunked encoding #47630
base: main
Are you sure you want to change the base?
Conversation
Review requested:
|
What is the context for this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a little more work. 🤗
@@ -866,6 +866,7 @@ function strictContentLength(msg) { | |||
); | |||
} | |||
|
|||
let chunkBuffer = Buffer.alloc(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this as a global variable will cause concurrent requests to interleave and become corrupt. The buffer needs to be scoped to the response object itself.
msg._send(crlf_buf, null, null); | ||
msg._send(chunk, encoding, null, len); | ||
ret = msg._send(crlf_buf, null, callback); | ||
chunkBuffer = Buffer.concat([chunkBuffer, Buffer.from(chunk)]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concatenating buffers is very slow. They require a memory allocation + memory copy. Just keep an Array
of buffers.
if (!this._headerSent && Buffer.byteLength(chunkBuffer)) { | ||
this._send(NumberPrototypeToString(Buffer.byteLength(chunkBuffer), 16), 'latin1', null); | ||
this._send(crlf_buf, null, null); | ||
this._send(chunkBuffer, null, null); | ||
this._send(crlf_buf, null, callback); | ||
chunkBuffer = Buffer.alloc(0) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done in nextTick (i.e., connectionCorkNT) otherwise, there is no point to all of this... the number of buffered chunks would always be 1.
@@ -1062,7 +1068,6 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) { | |||
this.socket.uncork(); | |||
} | |||
this[kCorked] = 0; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary change
}) | ||
); | ||
|
||
server.listen(3000, () => {}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't test anything related to the problem we are trying to solve.
Refs: nodejs/performance#57