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
ReadByte() from HttpWebRequest is slow. #7077
Comments
My results: (master/7f4a4965899) |
@EgorBo did you test this on windows? |
@mderoy yeah, Windows 10 16299.248 (fall creators update) UPD: confirmed - on bigger files the difference is huge (a second for .NET and more than 10 minutes for mono for 20mb txt file). |
The async-based web stack made a big difference for me, about 25 times faster, this was using a master build from today, but I only tested on Mac. |
When you're reading the response one byte at a time, each single byte needs to make one of more async operations internally. With my new code, your example calls The problem is simply that before the implementation can figure out that the entire buffer you're requesting to read is already buffered, it needs to go through a layer or intermediate checks. It needs to prevent concurrent async calls, setup a timeout cancellation and check for gzip or chunked encoding. |
Is there any specific reason why you are reading the response one byte at a time? To read a 300k file that way, you're doing over a million async requests. Reading even a 256 byte buffer at a time will reduce the time to just milliseconds. If you truly need to read one byte at a time, then something you could try is to wrap the stream that's returned from |
This came from a Unity customer. If the underlying issue can be mitigated (say by reading 256 bytes) we can respond and close. |
yes, it can be mitigated with using buffers instead of reading one byte at a time. |
@migueldeicaza I stumbled upon this thread in attempting to debug the same problem in Unity, however I'm using
Whereas this code runs in less than 1 second:
If I uncomment the line in the first function which outputs the "read" size, I note that the vast majority of the reads are |
Steps to Reproduce
Current Behavior
Downloading 300KB takes about 16.5 seconds from localhost
Expected Behavior
Downloading 300KB with .NET framework downloads the file from localhost in less than 1/10th of a second
On which platforms did you notice this
[ ] macOS
[ ] Linux
[ x ] Windows
Version Used:
Recent Master
Stacktrace
N/A
The text was updated successfully, but these errors were encountered: