emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

Refactor emscripten_fetch_* to use fetch instead of XHR

Open ifiddynine opened this issue 1 year ago • 2 comments

This adds support for streaming for Chrome, and plenty of optimization opportunities including request priorities, improved performance on web workers etc.

I intentionally kept the API the same as before (besides adding priority flags) - but it might make sense to change that as well in a future change.

ifiddynine avatar Jan 29 '24 04:01 ifiddynine

Thanks! This is very exciting.

Np! It helped us be way more responsive thanks to getting / processing responses faster. Plus it seems like fetch is way way faster in workers than XHR was.

I do wonder about loss of functionality though. In particular the indexdb stuff and also EMSCRIPTEN_FETCH_SYNCHRONOUS which IIRC cannot be implemented using the Fetch API?

My thinking re: IDB is that since fetch has built-in support for caching in the browser that support wasn't needed anymore. But we could add it back if there are other reasons for it? I did make sure to map the previous macros for caching options to the new fetch functionality.

Synchronous is a good point though, that crossed my mind. I'm not really a JavaScript guy, but is there a way can fake a synchronous operation by using await on the promise returned by fetch?

It looks like there are some good code size saving here. Can you compare the size of one of the fetch tests (with closure enabled) to see how much exactly?

Sure!

ifiddynine avatar Jan 29 '24 04:01 ifiddynine

Makes sense! I haven't had the time to work on this for a while, but if anyone wants to feel free to steal the PR and refactor / split into parts. I might get around to it at some point though. Mostly to make merging latest into our fork easier.

ifiddynine avatar Sep 04 '24 21:09 ifiddynine