Uh oh!
There was an error while loading. Please reload this page.
EP-003: stream.Readable#readInto - #27
Conversation
indutny
commented
Jun 1, 2016
cc @nodejs/collaborators @nodejs/streams |
| // Asynchronously read data into `buf.slice(offset, offset + length)` | ||
| // Invoke continuation with either error (`err`) or number of bytes | ||
| // read (`length`) | ||
| stream.readInto(buf, offset, length, (err, length) => { |
There was a problem hiding this comment.
It may be worthwhile going ahead and passing buf, offset and length to the callback as additional arguments. (or buf.slice(offset, offset + length)
There was a problem hiding this comment.
Agree, though passing slice will probably be in contrary to the performance reasons of this feature.
There was a problem hiding this comment.
Yeah, agreed. simply passing the additional buf and offset arguments on should be good enough.
| * [Public C++ Streams](001-public-stream-base.md) | ||
| * [ES6 Module Interoperability](002-es6-modules.md) | ||
| * [stream.Readable#readInto()](003-readable-read-into.md) |
There was a problem hiding this comment.
Could you remove this line and rename 003-* to XXX-*? Whoever merges the PR changes those, since another might land before this and all. :)
trevnorris
commented
Jun 2, 2016
Totally dig the idea. |
indutny
commented
Jun 2, 2016
So, does it mean that I need to change "DRAFT" to "ACCEPTED"? What is required for this? |
trevnorris
commented
Jun 2, 2016
@indutny Well, if it were possibly considered controversial then it would need to be voted on by the CTC. I would at least like to see more of the CTC give their thoughts before it's ACCEPTED. Meaning, if an EP reaches ACCEPTED then the PR accompanying it will definitely be accepted, and there shouldn't be much if any discussion between CTC members about the PR landing (this doesn't include other devs who feel the need to chime in). |
indutny
commented
Jun 2, 2016
@trevnorris makes sense. Thank you! |
indutny
commented
Jun 2, 2016
cc @nodejs/ctc then |
jasnell
commented
Jun 2, 2016
Fwiw, I'm +1 on this.
|
chrisdickinson
commented
Jun 2, 2016
Who is expected to call |
chrisdickinson
commented
Jun 2, 2016
(Also: is it possible that we define this for a subset of streams — maybe just |
indutny
commented
Jun 2, 2016
|
indutny
commented
Jun 2, 2016
Personally, I don't have much preference, but it seems to be better to have a wider support for it. |
benjamingr
commented
Jun 2, 2016
This is something I would have used plenty of times ( The proposal itself sounds reasonable to me. I'd make some stylistic changes to the code samples in the proposal but that's really not important. |
mcollina
commented
Jun 2, 2016
@indutny just have a section clarifying the relationship with pipe. |
bnoordhuis
commented
Jun 2, 2016
This proposal still has the issue that you need at least as many buffers as you have streams, doesn't it? Ideally, it would be possible to have a single buffer and read into that on demand. E.g.: conststreams=[/* ... */];constbuffer=newBuffer(256);for(conststreamofstreams){stream.on('readable',()=>{constn=stream.readInto(buffer,0,buffer.length);if(n<0)handleError(stream,n);elsehandleData(stream,buffer,n);});} |
| ### 2.2 Core Perspective | ||
| TLS, HTTP is now performed mostly within the C++ layer, raising the complexity | ||
| and making things less observable for the JavaScript user code. `readInto` may |
There was a problem hiding this comment.
"may be" is not very confidence building here
rvagg
commented
Jun 2, 2016
It's such a leaky abstraction tho, I'm not really keen on increasing the complexity of streams tbh and this certainly does that. I'd prefer if this were something we could keep private in core for its own use until we're comfortable that the wins are big enough to share with users. |
mcollina
commented
Jun 3, 2016
@rvagg that will be hard, mainly because it will probably leak into readable-stream at the next release. My concern is mainly related to the current non applicability of this to pipe(), to get "global" benefits. I'll be more than happy to "port" some of my MQTT stuff to |
trevnorris
commented
Jun 3, 2016
@rvagg What's unfortunate is that the idea is conceptually simple. Streams are what make everything else more complicated. I'd like to see this in core. Creating many buffers for incoming packets is the limiting throughput factor for TCP I/O. @bnoordhuis That's sort of the API I was hoping for. Problem is the I see the flow going something like so:
Well, that's a rough outline of what I was thinking. |
jorangreef
commented
Jul 21, 2017
Any progress on this? This would be really awesome. |
I'm still very interested in this as well. FWIW I just wrote my own implementation that is strictly limited to sockets and bypasses streams altogether to make things simple and straight-forward (although the It works like this: constsocket=net.connect({port: 12345,buffer: Buffer.alloc(65535),onread: (nread,buffer)=>{// buffer argument === buffer property above// return `false` explicitly to stop reading, `socket.read(0)`// or similar should restart it}});Example "malloc mode" result: Example new mode result: |
mcollina
commented
Aug 21, 2017
I would love to have something like this implemented. I just do not see how we can achieve that with the current stream API. I'm open to suggestions. This might be relevant to the discussion: https://github.com/mcollina/syncthrough. It's like Transform but sync (it respects the Streams 3 contract, apart from the buffering). Because it's sync, we can guarantee that the chunk has been processed afterwards. |
mscdex
commented
Aug 21, 2017
Perhaps we will have to just skip streams to make it simple and/or doable. I think starting with |
jorangreef
commented
Aug 22, 2017
Thanks @mscdex, would you be able to provide me with a copy of that code (even very raw)? I don't mind doing more work to open source it. |
mscdex
commented
Aug 22, 2017
@jorangreef I just pushed what I currently have to https://github.com/mscdex/io.js/tree/net-socket-static-buffer. I'm sure some of the C++ changes could be designed better but meh... |
Trott
commented
Jun 12, 2018
Closing as this seems inactive. By all means, comment or re-open if this is still an ongoing concern, although I suspect it should be moved to a more active repository (probably the main node repo) if that's the case. |
See: nodejs/node#6923