Re: [whatwg/streams] Allow other specifications to create readable byte streams (#1121)

> I think making the implementation-defined value part of the streams specification would give the idea that this value must be the same for all streams.

Good point. I agree that at the very least this would be something we'd have to wordsmith around.

> Note that ReadableByteStreamControllerEnqueue already does this. 😉
>
> In the limit, we could use "enqueue bytes" everywhere and remove "respond to BYOB request" entirely, instead leaving it up to implementations if they want to optimize by responding to the BYOB request where possible.

Heh, thanks for the reminder... Indeed, I'm not sure what the best route is for making it clear that writing directly into the buffer is preferred, while also allowing spec authors some freedom to use the prose they're used to (e.g. "getting byte sequences from the OS" or "getting byte sequences from the network").

> My only concern with making this mandatory is the potential to introduce developer-visible side effects that prevent optimizations. 

Thanks very much for outlining the concern and details here. I agree that if we used autoAllocateChunkSize in the fashion I described above the ArrayBuffer would be mandated to be the same size every time and could not be trimmed to fit the data more exactly.

At a high level:

- If your consumer is using a BYOB reader, then you really should give them back the full ArrayBuffer, not trimmed.

- But if your consumer is using a default reader, it'd be nice to allow trimming.

To accomplish this today I guess you would *not* pass autoAllocateChunkSize, and then you'd branch:

- If there's a BYOB request, try to fill the BYOB request's buffer, and even if it's not filled, give them back the full buffer. (In this scenario, does options["bufferSize"] just get ignored?)

- If there's no BYOB request, then use options["bufferSize"] to request bytes from the OS, and enqueue the resulting buffer (which might be smaller than options["bufferSize"]).

This seems reasonable, albeit more ceremony than I was envisioning. What do you think?

If it seems OK then maybe we should make this the model everyone uses, and avoid using autoAllocateChunkSize.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/1121#issuecomment-815051145

Received on Wednesday, 7 April 2021 16:27:52 UTC