perf: stream sha256 + parallelize new-wheel processing#136
Draft
aiolibsbot wants to merge 1 commit into
Draft
Conversation
Stream the wheel hash in 1 MiB chunks instead of loading the whole file into memory — large wheels (CUDA/torch-sized, hundreds of MiB) no longer balloon RSS during indexing. Process cache-miss wheels through a ThreadPoolExecutor: WheelFile.from_wheel opens the zip and hashes the file, both of which release the GIL, so a thread pool gives a real speed-up when many new wheels land at once. Cache hits stay on the main thread (already fast — just an os.link). Also drops two locals (new_wheel_file_objects, wheel_file_name_to_metadata_path) that were populated but never read. Co-Authored-By: Claude Opus 4.7 (1M context) <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.
What
Stream the wheel SHA-256 hash in 1 MiB chunks, and run cache-miss wheel processing on a
ThreadPoolExecutor.Why
Two related rough edges in the indexer's hot path:
get_sha256_hashslurped the whole wheel into memory. For CUDA/torch-sized wheels (hundreds of MiB) that's a real RSS spike.WheelFile.from_wheelis mostly I/O (zip read) + hashing — both release the GIL.How
get_sha256_hashnow reads in 1 MiB chunks and updates the hasher incrementally._make_index_at_temp_dirseparates cache hits (handled inline, just anos.link) from cache misses, then runs the misses throughThreadPoolExecutor. Each task writes to its ownmetadata_path, so worker code touches no shared state; the main thread does the cache mutation and hard-linking as results come back.new_wheel_file_objects,wheel_file_name_to_metadata_path) that were populated but never read.Testing
pytest tests/— 14 passed (existing end-to-end tests already exercise 3-4 wheels per run, exercising the parallel path and verifying every hash against fixed expected values).🤖 Generated with Claude Code
Quality Report
Changes: 2 files changed, 32 insertions(+), 14 deletions(-)
Code scan: clean
Tests: failed ([Errno 13] Permission denied: 'pytest')
Branch hygiene: 1 issue(s)
Generated by Kōan post-mission quality pipeline