stream: improve Readable.read() performance#7077
Conversation
|
/cc @nodejs/streams |
|
should buffer list maybe live in the internals folder ? |
|
@calvinmetcalf Debatable but I left it there since it's only used by Readable and it's better if Readable isn't referencing anything from |
|
I can extract that other file easily, I'm more worried about exporting that from readable which is not on the api |
|
@calvinmetcalf I don't understand what you mean by "is not on the api." |
|
sorry, misspoke, I meant that I didn't like exporting that new thing from readable |
|
@calvinmetcalf I can remove it if necessary I suppose, but then we'd end up duplicating some of it in the tests I had to modify. I thought it would be better not to have to keep two separate "implementations" in sync. |
|
I was thinking that if that file got moved to something in internal, then you could just require that for the tests and require it for from stream_readable and don't worry about the readable-stream module, it won't be much of an inconvenience. |
e90c652 to
1ae67c9
Compare
|
@calvinmetcalf Ok, moved to internal. |
1ae67c9 to
47d6cc0
Compare
lib/internal/streams/BufferList.js
Outdated
There was a problem hiding this comment.
Do you think it could help to create an Entry class to increase property access performance?
There was a problem hiding this comment.
I just tried it and it doesn't seem to make any real difference. If anything it seems to slow things down a little bit.
|
/cc @nodejs/collaborators Anyone have any comments/questions/LGTMs on this? |
lib/_stream_readable.js
Outdated
There was a problem hiding this comment.
I'm not sure on the style guide on this, but the outer braces seem useless.
There was a problem hiding this comment.
You mean the parens? shrug I always add that when "assigning" a ternary statement to a variable as it seems more readable/clear to me.
There was a problem hiding this comment.
I noticed :) I don't really mind, just curious if there's any consensus on this. No blocker, no worries.
And sorry, yeah, parens (I, non-native English speaker, always get these mixed up... sigh)
f1922f1 to
1f2fbc2
Compare
1f2fbc2 to
729b645
Compare
|
First read through looks good but I'll have to go through in more detail tomorrow. In general tho, if @nodejs/streams is happy, then ++ |
|
Do we have a CITGM run? If that passes.. LGTM. just with one catch.. Let's give this a long time before we backport. |
|
the job was aborted, should we kick it off again? |
|
@mcollina It was aborted most likely because the ppcle machine is/was still down. The lodash failure on OSX1010 looks like an npm or citgm failure since it failed on installation of the package. Otherwise citgm is green. |
|
LGTM as semver-minor. |
|
@mcollina Why is this |
|
@Fishrock123 avoiding possible breakages in a patch release. IMHO performance optimizations are semver-minor, as performance is a backward-compatible feature. |
|
@mcollina So you are saying this is How this works is, in this order:
|
no and no. This is a performance optimization, e.g. a new feature for me. |
|
So... don't land on LTS is what I'm getting out of this. :) |
|
@Fishrock123 I think this one will be fine on LTS, but I would recommend porting it after some months, not weeks. Something like "land when the new LTS is out". |
|
@Fishrock123 @mcollina just re your above conversation, this ended up breaking duplexify (https://www.npmjs.com/package/duplexify) because it expected the _buffer to be an array |
|
I feared something like that would have happened. I think we should make a final decision either to semver I'm happy we got this early (before a backport to readable-stream). |
|
They're clearly private. If people want to manipulate them, we can expose public API for that. The duplexify package authors could've pushed/asked for that, and still can imho. |
|
@mcollina could you open a separate issue for the semver discussion so we don't take over this one? for the record i think reading some of the properties in _readableState is essential for a bunch of use-cases. like figuring out if a stream is in objectMode, figuring out if it ended but still has data in its read buffer etc. |
|
@mafintosh done ^ |
Checklist
Affected core subsystem(s)
Description of change
read()performance is improved most by switching from an array to a linked list for storing buffered data. However, other changes that also contribute include: making some hot functions inlinable, fasterread()argument checking, and misc code rearrangement to avoid unnecessary code execution.These improvements only exist for when
nis supplied toread(), otherwise performance is the same.Note: I did change how negative
nvalues are interpreted when in object mode. Before this PR, negativenvalues were interpreted as 1 inhowMuchToRead(). I changed this to instead return 0 to match how negativenvalues are interpreted for non-object mode streams.Results from the included benchmarks: