Parallelize keg downloads with ThreadPoolExecutor#111
Open
Smiie-2 wants to merge 1 commit into
Open
Conversation
Replace sequential per-file HTTP fetching in keg with concurrent.futures.ThreadPoolExecutor (32 workers) for both the metadata (archive indices) and data (loose files) download phases. Also fix all os.makedirs calls in keg/keg/cdn.py to use exist_ok=True to prevent race conditions when multiple threads create the same directory simultaneously. With 21,951 loose files to download, this reduces install time from ~36 hours (sequential, ~6s/file) to ~1-2 hours (32 parallel workers). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
keg fetches every file sequentially — one HTTP request completes before the next starts. For a full Hearthstone install this means downloading ~21,951 loose files at ~5-6s each, totalling ~36 hours.
The bottleneck is network round-trip latency, not bandwidth, so parallelism helps significantly.
Fix
Replace the sequential
for item in queue.drain(): item.fetch()loops inkeg/bin/ngdpwithThreadPoolExecutor(32 workers) for both:Also fixes all
os.makedirscalls inkeg/keg/cdn.pyto useexist_ok=True, preventing race conditions when concurrent threads try to create the same directory.Result
~21,951 loose files at ~5s each:
Testing
Verified on EU region — full fresh install completed successfully with parallel downloads active. Game launches and is playable.
🤖 Generated with Claude Code