Repository navigation
Stream indexes in fetch/gc/stats to optimize memory usage - #3
Merged
Merged
Conversation
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.
Fixes four whole-genome scaling failures found on a 7.4 TB / 241-species MAF, where every command that read an index loaded it fully into memory:
fetch -m scaffoldtried to read a whole scaffold in one allocation. In the case of a single 597 GBread()it raisedMemoryError, whosestr()is empty (hence a blank [ERROR] in the log), and then reported "Wrote" and exited 0 with a 0-byte file, so downstream pipelines consumed the failure as success. Now streamed in bounded chunks, and scaffold failures fail the run.gcOOM-killed at 62 GB just parsing the 35 GB index. Streamed: peak went from linear (~32 GB extrapolated) to flat ~1.5 MB.statshad the same pattern; also streamed.fetchblock mode built a dict per block (~67 GB at 233 M blocks). Regions are now sorted into index order and each worker streams its own span, using a binary search over the index file's bytes. On 20k real regions: 3.30 GB → 47 MB peak RSS, 8.9x faster, all 20,000 outputs byte-identical across none/gz/bgzip.Two pre-existing bugs surfaced along the way:
statsconcatenated per-chunk block rows in lexicographic filename order (task10 before task2), scramblingblock.tsvfor any run with ≥10 chunks; andfetch's no-output accounting read the region's start coordinate instead of its block count, so any region starting at 0 was miscounted as empty (failing runs that had worked) while regions elsewhere finding zero blocks were counted as written.Behavior changes to note: block mode now requires
<maf>.scaffold.idxalongside the block index; non-overlap outcomes (no-overlap, missing scaffold, all-regions-empty, count/fraction thresholds) now warn and exit 0 instead of failing; stats'block.tsvrow order changed for multi-chunk runs.101 tests passing, including new streaming/scaffold-mode suites.
🤖 Generated with Claude Code (Opus 5)