Revisit 2048 byte buffer used for HTTP downloads
I think 2048 byte buffer is too small, and might cause more CPU overhead (due to lot of async callbacks) and also doesn't work good for faster network speeds. Refer #866 (comment 1957592).
After increasing the buffer size from 2K to 8K, there was 3-5x increase in download speeds.
I think this number should be a dynamic value based on how fast the download progresses.
Source: https://gitlab.gnome.org/GNOME/gnome-boxes/-/blob/main/src/downloader.vala#L148
public async void download_from_http (Download download, Cancellable? cancellable = null) throws GLib.Error {
int64 current_num_bytes = 0;
try {
var input_stream = yield session.send_async (msg, Priority.DEFAULT, cancellable);
while (true) {
uint8[] buffer = new uint8[2048];
var num_read = yield input_stream.read_async (buffer, Priority.DEFAULT, cancellable);
...
...
yield cached_file_stream.write_all_async (buffer, Priority.DEFAULT, cancellable, out bytes_written);
if (total_num_bytes > 0)
download.progress.progress = (double) current_num_bytes / total_num_bytes;
}
} catch (GLib.Error e) {
err = e;
}
}