Skip to content

Commit

Permalink
Increase the default HTTPClient download chunk size to 64 KiB
Browse files Browse the repository at this point in the history
This improves download speeds at the cost of increased memory usage.

This change also effects HTTPRequest automatically.

See godotengine#32807 and godotengine#33862.

(cherry picked from commit 1335709)
  • Loading branch information
Calinou authored and HEAVYPOLY committed Dec 14, 2020
1 parent 8cb5737 commit 3b606a9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion core/io/http_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ HTTPClient::HTTPClient() {
ssl = false;
blocking = false;
handshaking = false;
read_chunk_size = 4096;
// 64 KiB by default (favors fast download speeds at the cost of memory usage).
read_chunk_size = 65536;
}

HTTPClient::~HTTPClient() {
Expand Down
2 changes: 1 addition & 1 deletion doc/classes/HTTPClient.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
<member name="connection" type="StreamPeer" setter="set_connection" getter="get_connection">
The connection to use for this client.
</member>
<member name="read_chunk_size" type="int" setter="set_read_chunk_size" getter="get_read_chunk_size" default="4096">
<member name="read_chunk_size" type="int" setter="set_read_chunk_size" getter="get_read_chunk_size" default="65536">
The size of the buffer used and maximum bytes to read per iteration. See [method read_response_body_chunk].
</member>
</members>
Expand Down
4 changes: 2 additions & 2 deletions doc/classes/HTTPRequest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,9 @@
<member name="body_size_limit" type="int" setter="set_body_size_limit" getter="get_body_size_limit" default="-1">
Maximum allowed size for response bodies.
</member>
<member name="download_chunk_size" type="int" setter="set_download_chunk_size" getter="get_download_chunk_size" default="4096">
<member name="download_chunk_size" type="int" setter="set_download_chunk_size" getter="get_download_chunk_size" default="65536">
The size of the buffer used and maximum bytes to read per iteration. See [member HTTPClient.read_chunk_size].
Set this to a higher value (e.g. 65536 for 64 KiB) when downloading large files to achieve better speeds at the cost of memory.
Set this to a lower value (e.g. 4096 for 4 KiB) when downloading small files to decrease memory usage at the cost of download speeds.
</member>
<member name="download_file" type="String" setter="set_download_file" getter="get_download_file" default="&quot;&quot;">
The file to download into. Will output any received file into it.
Expand Down

0 comments on commit 3b606a9

Please sign in to comment.