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

Streaming APIs #31

Closed
jamesplease opened this issue Feb 21, 2018 · 4 comments
Closed

Streaming APIs #31

jamesplease opened this issue Feb 21, 2018 · 4 comments

Comments

@jamesplease
Copy link
Owner

jamesplease commented Feb 21, 2018

I think that the only way to support streaming APIs is to clone the responses rather than trying to copy the stream over. Atm the responseType methods read the stream to completion before returning it, which isn't ideal.

This is an unfortunate situation. ☹️


Update: One idea would be to tee the stream and send that out to each consumer, but it doesn't resolve the responseType problem.

@jamesplease
Copy link
Owner Author

jamesplease commented Apr 4, 2018

Here is a WIP spec on FetchObserver. It lists some states that would help with providing streaming states.

Atm, here is what I am thinking:

  • responseType option is removed
  • response is cloned twice under-the-hood.
    • one unread version is kept around in memory to be cloned again for request deduplication
    • the other cloned response body is streamed out until completion to keep track of a streaming status
  • that's all folks

Things to verify:

  • memory footprint for larger downloads (I should test with files around 10mb)

My prediction is that for cached requests, the memory footprint is x1. For "active" requests (requests that are cached and that you are using), the footprint is x n, where n+1 is the number of places you are using the data.


There may be a way to make it so that the data that has been read once is made available everywhere, too, without wrapping methods. That would make the footprint x1 and give all of these features.

@jamesplease
Copy link
Owner Author

jamesplease commented Mar 10, 2019

It's been awhile, but I figured I'd post an update with a test that I ran: Chrome hides the download resource out of the JS heap size until it is read, so it is going to be pretty challenging to determine the memory consequences of cloning a response...

From what I can gather, the spec doesn't say anything about where the data has to be stored, so some browsers could do this in an efficient manner, and others could do it inefficiently.

@jamesplease
Copy link
Owner Author

Download size isn't the only concern here. res.json() for large payloads will take a non-negligible amount of time.

Perhaps there's a way to save the results of these operations into the cache...is that getting too complicated?

@jamesplease
Copy link
Owner Author

Gonna close and stick with the responseType API for now due to the previous comment.

The only solution I can think of atm is to wrap the Response object, but that adds a considerable amount of complexity to this lib that I'm not convinced is worth it atm.

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

No branches or pull requests

1 participant