-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[fetch] Do not collect all data when streaming requests. #26048
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
[fetch] Do not collect all data when streaming requests. #26048
Conversation
Previously, when `EMSCRIPTEN_FETCH_STREAM_DATA` was used we would collect all the streamed data chunks and create the full response when finished. This caused excessive memory usage. Now we leave it up to the user to process the data and collect it as needed.
|
See #25383 (comment) |
|
/cc @inolen |
|
Is this a breaking change? |
No, the old code that used the firefox onprogress events wouldn't pass all the data when finished to the C API. There's a test for it in
|
|
But I'm still confused, the description says
What if the user doesn't do that properly - could existing code not break? |
|
Let me reword that... I was thinking of it from the perspective of the FetchXHR polyfill not the C API. The polyfill behavior does change (we no longer collect all the bytes), but this isn't visible to anyone using the emscripten C API. |
|
Hey @brendandahl thanks! This looks great for not allocating the entire response when streaming. I was going to post a patch in that comment thread, but I got a bit distracted and haven't had time to run tests on my changes. There are two other issues with the code right now that I noticed when using this with thousands of files. These aren't directly related to your new code, so I can always open a new PR if desired - 1.) saveResponseAndStatus leaks the allocated data when using the streaming mode. Since xhr.response is NULL, ptr / ptrLen remain 0, and it then overwrites ptr with 0 leaking the allocated data. Here was my current WIP state - |
|
I haven't looked into the other issues you mentioned yet. A separate PR would be good. We should probably run some of the fetch tests with lsan. |
kripken
left a comment
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.
Now I see, thanks!
Previously, when
EMSCRIPTEN_FETCH_STREAM_DATAwas used, we would collect all the streamed data chunks and create the full response when finished in the XHR polyfill. The full response is not used by the C fetch API, so we can avoid storing it when streaming is enabled.