Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Latency-bounded reads #1270

Open
nidhijaju opened this issue Apr 7, 2023 · 4 comments
Open

Latency-bounded reads #1270

nidhijaju opened this issue Apr 7, 2023 · 4 comments

Comments

@nidhijaju
Copy link
Contributor

Many media-related use cases complain that there's a lot of overhead from unnecessary wakeups from read(), as streaming network reads use too much CPU and power. They would benefit from latency-bounded reads i.e. "try to fulfill read() once, 10ms from now, with all the data you've received between now and then".

In addition to min in #1145, it might be good to have something like deadline as an option for read() to allow for latency-bounded reads.

cc @ricea

@saschanaz
Copy link
Member

Can the purpose be fulfilled by something like pull(c) { c.enqueue(data); return new Promise(r => setTimeout(r, 10)) }? Another pull won't happen until the promise resolves, right?

@ricea
Copy link
Collaborator

ricea commented Jun 30, 2023

Can the purpose be fulfilled by something like pull(c) { c.enqueue(data); return new Promise(r => setTimeout(r, 10)) }? Another pull won't happen until the promise resolves, right?

This doesn't help with platform streams like Response body.

@saschanaz
Copy link
Member

saschanaz commented Jun 30, 2023

Hmm yeah, #616 could allow TransformStream based control:

stream.pipeThrough(new TransformStream({
  transform(chunk, c) {
    c.enqueue(chunk);
    return new Promise(r => setTimeout(r, 10));
  }
}))

For now this only works for non-BYOB readers, so the usefulness is limited for byte streams.

@MattiasBuelens
Copy link
Collaborator

I don't think this can be solved in the underlying source. Your example adds a 10ms delay between each chunk, whereas the OP wants to add a 10ms delay between each read(view). That single read(view) could be populated with bytes from multiple chunks, if the view is large enough and the deadline has not been hit yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants