Allow reading multiple data chunks per frame in a single-threaded HTTPRequest#120462
Open
NoNormalDev wants to merge 1 commit into
Open
Allow reading multiple data chunks per frame in a single-threaded HTTPRequest#120462NoNormalDev wants to merge 1 commit into
HTTPRequest#120462NoNormalDev wants to merge 1 commit into
Conversation
12316ac to
73d0c73
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem(s) solved by this PR
Additional information
When
use_threads = falseon aHTTPRequest,incoming data gets processed on the main thread. Right now, only one chunk gets read per frame, which means throughput is effectively capped atdownload_chunk_size * FPS, which can be problematic (see the linked issue for more details)This PR lets multiple chunks be processed within a single frame.
I also added a
read_time_limitproperty that limits how much time can be spent reading data per frame (this only matters whenuse_threads = false, it's not used otherwise). Without a limit like this, a fast connection could end up stalling the main for seconds even. At least one read still always happens per frame regardless of the limit.Here is some data from a project running at 20 FPS, downloading a 16 MiB file on a simulated 10 MB/s network (localhost with a python server):
download_chunk_sizeAuthor disclosure
I used Claude to discuss possible approaches, though honestly most of its suggestions were awful, and to review the changes for mistakes before pushing.
All the code is mine.