Slow Http transfer rate using Flutter/Dart on Windows App

Viewed 256

A bit stuck and wondered if anyone got the same issue. I have Windows 10 Flutter/Dart App that is downloading large (1GB) files from AWS. Using the same download on same machine but issuing a curl.exe command I get a sustained 65MB/sec. Requesting same file from same location using http.dart I'm only getting 5MB/Sec. I've read all the docs from http.dart and can't see what would be causing this. I've also searched online and only found a http slowdown on iOS for Flutter/Dart. Both downloads are running through same 1Gib connection and onto a SSD with plenty of room. No other intensive ops are running. Resource Monitor shows that CPU use is low, Disk access is minimal, Memory use is low, and Network use is only 5% of 1 GiB. "query" is purely the filename and location. I wondered whether it could be the port that is being used is restricting speed or some other network issue outside of the code. I'm going to try and run the code on a different PC to check if it's machine related. I tried building in debug and release.

final response1 = await http.get(
Uri.parse(query),
headers: {HttpHeaders.authorizationHeader: 'Bearer $bearerToken', 'range': 'bytes=$chunkStart-$chunkEnd'});

Thanks for any help.

1 Answers

It's hard to say with confidence exactly what is going on here, but maybe some of this will be useful:

Firstly, when doing any performance work in Flutter, make sure you are running in profile mode (e.g. by running flutter run --profile or equivalent). Debug mode performance is not representative and seeing 10x speedups for certain operations is not unheard of.

It's also possible the windows implementation of the http library is just poorly optimised. You may find another library with it's own implementation, but I wouldn't be too optimistic about that (it's likely that any other http packages rely on package:http under the hood anyways).

However, if curl is giving much better performance, it may be possible to call curl directly from Flutter using Process.run. However, it's worth checking whether there are currently any issues running command line tools from inside Flutter. You would then also have to package a version of curl with your application.

It may be more feasible to use FFI, particularly if you have familiarity with C/C++/Rust, or even MethodChannels (although there is fairly limited documentation on using MethodChannels on Windows). Another alternative might be something in package:win32 for calling native win32 APIs

Best of luck :)

Related