mirror of https://github.com/nodejs/node.git
stream: Short-circuit buffer pushes when flowing
When a stream is flowing, and not in the middle of a sync read, and the read buffer currently has a length of 0, we can just emit a 'data' event rather than push it onto the array, emit 'readable', and then automatically call read(). As it happens, this is quite a frequent occurrence! Making this change brings the HTTP benchmarks back into a good place after the removal of the .ondata/.onend socket kludge methods.pull/5010/head
parent
967b5dbb45
commit
c0e70354db
|
@ -147,17 +147,24 @@ function readableAddChunk(stream, state, chunk, encoding, addToFront) {
|
|||
if (state.decoder && !addToFront && !encoding)
|
||||
chunk = state.decoder.write(chunk);
|
||||
|
||||
if (!addToFront)
|
||||
state.reading = false;
|
||||
|
||||
// if we want the data now, just emit it.
|
||||
if (state.flowing && state.length === 0 && !state.sync) {
|
||||
stream.emit('data', chunk);
|
||||
stream.read(0);
|
||||
} else {
|
||||
// update the buffer info.
|
||||
state.length += state.objectMode ? 1 : chunk.length;
|
||||
if (addToFront) {
|
||||
if (addToFront)
|
||||
state.buffer.unshift(chunk);
|
||||
} else {
|
||||
state.reading = false;
|
||||
else
|
||||
state.buffer.push(chunk);
|
||||
}
|
||||
|
||||
if (state.needReadable)
|
||||
emitReadable(stream);
|
||||
}
|
||||
|
||||
maybeReadMore(stream, state);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue