manifest: hash through one reused buffer, halving peak chunk memory per worker (OLD-4922) #129
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!129
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/129/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@natterman12 on GitHub · 2026-11-24 02:24 UTC · original
manifest/reuse-hash-buffer→main· +53 −9 · 2 files · 1 commits · merged 2026-11-24 03:10 UTCClaimed in the coordination issue as: OLD-4922 (#14; old issue "manifest: reuse the hash input buffer to halve peak chunk memory per worker", indexed in #18)
What and why
tools/manifest.py,_hash_file()read the file withf.read()allocates the next 8 MiBbytesobject whilechunkstill refers to the last one, so each hashing worker holds two chunks at its peak. With--jobs Nthat is 16 MiB times N for the read buffers alone.It now fills one
memoryview-backedbytearraywithreadinto(), the waymanifest_verifier.sha256_file()already does. Sizes, digests, the manifest format and the three change-during-hashing checks are unchanged.Measured
tracemallocpeak of one_hash_file()call on a 320 MiB temporary file (synthetic bytes, Windows 11, Python 3.15.2, NVMe):The throughput difference is within what I would expect from run-to-run noise on a warm cache; I am only claiming the memory figure.
Tested
No GPU involved. Windows 11, Python 3.15.2:
python -I tests/test_manifest.py: OK, 39 tests (1 skipped, as onmain)python -I tests/test_manifest_verifier.py,test_text_write_line_endings.py,test_text_encoding.py: OKtest_hashing_reuses_one_chunk_buffer: six 1 MiB chunks plus a partial one must hash correctly with a peak under 1.5 chunks. It fails onmain(peak 2,098,046 bytes for a 1,048,576-byte chunk).test_hashing_follows_short_reads: areadinto()that returns 7 bytes at a time still hashes every byte once.test_same_size_change_during_read_keeps_the_previous_manifest: it hookedstream.read, which the tool no longer calls, so it now hooksstream.readinto. Same edit, same expectedManifestError.AI-assisted: yes (Claude Code)
Checklist
docs/design.md, with how it was confirmed. (not applicable: no translator change)🤖 Generated with Claude Code