Why is HttpWebRequest Slower than UnityWebRequest for Bundle Downloads?

Hello everyone,

I’ve been working on downloading asset bundles in Unity using both HttpWebRequest and UnityWebRequest. I’ve noticed that HttpWebRequest takes significantly longer to download bundles compared to UnityWebRequest.Is there a specific reason for this?I suspect it might be related to how UnityWebRequest is optimized for Unity’s environment, including better handling of asynchronous operations.

Has anyone else experienced this? Any insights or benchmarks would be appreciated!

Thanks!

Hey!

We’d consider this expected behaviour. The UnityWebRequest API does a number of optimizations under the hood - for example if your data needs to be recompressed, then it will be recompressed as its streamed down vs. doing that at the end of the process.

I would recommend that you take a look at the HTTP requests with a capture tool like fiddler or wireshark and really compare what is different with the requests, including looking at all the headers and the response sizes and timings. Its possible that you can tweak your usage of HttpWebRequest to match what Unity does.

As George-Ing mentions, Unity is able to start accessing the file as it is streamed down, and depending on the compression settings it may be recompressing the content during this process. In some cases the file just stays in memory which skips the local file I/O.

But if there is no compression change then I think the simple case of getting the AssetBundle downloaded to a locally file shouldn’t fundamentally be slower when using other HTTP libraries, if the same sort of HTTP requests are made.

It is also important how performance is measured and what exactly code does.
UnityWebRequest feeds data to asset bundle load on the fly in background thread. We don’t know how you’ve set up HttpWebRequest.