-
Notifications
You must be signed in to change notification settings - Fork 66
Conversation
cc @nodejs/collaborators @nodejs/streams |
003-readable-read-into.md
Outdated
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, though passing slice
will probably be in contrary to the performance reasons of this feature.
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.
Yeah, agreed. simply passing the additional buf
and offset
arguments on should be good enough.
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.
Ack.
000-index.md
Outdated
@@ -2,3 +2,4 @@ | |||
|
|||
* [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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you remove this line and rename 003-*
to XXX-*
? Whoever merges the PR changes those, since another might land before this and all. :)
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.
Ack. 👍
Totally dig the idea. |
So, does it mean that I need to change "DRAFT" to "ACCEPTED"? What is required for this? |
@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). |
@trevnorris makes sense. Thank you! |
cc @nodejs/ctc then |
Fwiw, I'm +1 on this.
|
Who is expected to call |
(Also: is it possible that we define this for a subset of streams — maybe just |
|
Personally, I don't have much preference, but it seems to be better to have a wider support for it. |
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. |
@indutny just have a section clarifying the relationship with pipe. |
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.: const streams = [ /* ... */ ];
const buffer = new Buffer(256);
for (const stream of streams) {
stream.on('readable', () => {
const n = stream.readInto(buffer, 0, buffer.length);
if (n < 0)
handleError(stream, n);
else
handleData(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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"may be" is not very confidence building here
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. |
@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 |
@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. |
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: const socket = 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:
|
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. |
Perhaps we will have to just skip streams to make it simple and/or doable. I think starting with |
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. |
@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... |
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