Repository navigation
Generate time and memory improvements - #16
Merged
Merged
Conversation
Three things took most of the read pass, and each now does less work for the same answer: - A tag with an N is compared with a sequence in the stretches between its N's, as whole strings (`_n_tag_fits`). - The gapped prescreen makes a design tag's bit masks once, stops at the first of its two passes that settles the question, and `_gapped_edits` skips the Alt tag when the Ref tag's bound is already too far. - `PrimerIndex.match` takes its search up from its state after 12 bases, which reads of one amplicon share. Most of a run's memory is sequences seen once or twice: - `apply_partial_reads` adds partial reads without copying a sample's tables. - Protection is decided from the sequences that reach a route's read count in some sample (`_could_pass`). No other sequence can pass. - `finalize_counts` lets each sample as read go once it is denoised. - The per-sequence quality tallies stay in the worker unless the quality route is on. They are still counted and cached. With 8 jobs: pecan (376 samples) 1,376 s to 657 s and 15.9 GB to 7.0 GB, alfalfa (356) 464 s to 262 s and 9.4 GB to 3.8 GB, sweetpotato (80) 381 s to 204 s and 3.4 GB to 1.75 GB. Memory is the main process's peak footprint. On all three the table, the variants sidecar and the QC JSON are the same byte for byte, and so are the read-pass caches. `tests/test_same_answers.py` sets each shortcut beside the plain computation it stands in for.
Both sides add an argument to the sample workers: development the gzip level of the caches, this branch whether the quality tallies come back. The workers now carry both.
The primer search no longer keeps a read start that leads to no primer. Reads that match no primer share few starts, and keeping theirs added about 100 MB to a worker on a sample of random reads (189 MB against 86 MB). On real samples the store is now 5 MB to 13 MB. The gapped prescreen runs the design tag's pass first, because its bit masks are cached. No decision changes on 136,628 calls recorded from one pecan, one alfalfa and one sweetpotato sample. collect_evidence has one docstring, finalize_counts says its list must be mutable, and _n_tag_fits says it expects one length. Five new tests: the primer search beside a primer-by-primer comparison, the store without dead starts, an emptied store, release across worker processes, and Alt tags several bases from the Ref tag. The quality-tally test now also reads a cache written by a run that returned no tallies. The three cohorts' tables, variants sidecars and cache contents are the same as before these changes, and the QC files are the same apart from the time stamp and the output paths. The development record now says so, gives back-to-back times against 0.13.0 for sweetpotato and alfalfa, and gives the workers' memory.
There was a problem hiding this comment.
🟢 Approval recommended
There are no active review issues for the pipeline optimization changes.
No open issues 🎉
What changed in this PR
Optimizes the generate pipeline to reduce runtime and memory use while preserving results.
Changes:
- Speeds up gapped alignment, primer matching, and N-tag resolution.
- Reduces copying and retained sample data during processing.
- Adds equivalence tests and documents performance measurements.
| File | Description |
|---|---|
tests/test_same_answers.py |
Adds 17 tests comparing shortcuts with baseline behavior. |
madcats.py |
Implements computation shortcuts and memory-saving processing. |
docs/src/development/changelog.md |
Reports measured runtime improvements. |
docs/DEVELOPMENT.md |
Documents optimizations, benchmarks, and expanded test coverage. |
Review effort: Balanced
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.
This pull request introduces several performance optimizations and memory improvements to the core pipeline, especially in the handling of gapped alignment, primer matching, and N-tag resolution. It also updates documentation to reflect these improvements and adds new tests to ensure correctness of shortcut paths that save time or memory.
Performance and memory improvements:
gapped_prescreenfunction now accepts anenoughparameter, allowing early termination when the lower bound is already within the threshold, and caches design pattern masks for faster repeated use. This change speeds up edit distance checks and reduces redundant computation. [1] [2] [3] [4]PrimerIndex.matchmethod now memoizes search states after a fixed number of leading bases, enabling shared computation across reads from the same amplicon and reducing per-sample memory usage. [1] [2] [3]_n_tag_fitsfunction and revisedresolve_n_tagslogic more efficiently assign ambiguous tags to concrete sequences, distinguishing between plain and coded pools and using stretch-based comparison where possible. [1] [2]Documentation and testing:
DEVELOPMENT.mdandchangelog.mdfiles now reflect the improved run times, memory usage, and the correctness of shortcut paths, with new sections describing the rationale and measurements behind the changes. [1] [2] [3]test_same_answers.py, that verifies each shortcut path produces the same results as the plain computation, increasing the total number of tests and files. [1] [2]These changes collectively result in 41–47% faster execution on key cohorts, a significant reduction in memory usage, and improved maintainability and correctness of the codebase.