Repository navigation
Fasta.fetch: size the output buffer from the intervals and free it - #100
Open
DylanCosto wants to merge 2 commits into
Open
DylanCosto wants to merge 2 commits into
DylanCosto wants to merge 2 commits into
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.
For a list of intervals,
pyfastx_fasta_fetchallocatesstrlen(seq) + 1bytes, one chromosome's worth, and never frees it. That causes three problems:strlen, so repeated exon extraction is slowfetch('chr', [(1, n), (1, n)])aborts with heap corruption)The leaked buffer also applies to the single-interval form.
This converts and validates all intervals first, allocates exactly the total requested length, frees it after building the result, and routes every error through a single cleanup path. List arguments are snapshotted as tuples before integer conversion, since
__index__can run Python code. Integer subclasses and list/tuple subclasses behave as before.The new validation raises
ValueErrorfor an empty interval list,start < 1orendpast the end of the sequence. Before, those read outside the buffer.On a cached 25 Mb chromosome, 1,000 two-exon fetches drop from about 0.73 s to 0.3 ms. On a 1 kb contig, peak RSS for 50,000 fetches drops from about 72 MB to 19 MB. Output is identical: I checked 4,000 results against independently sliced plain and gzipped FASTA.
The existing
fetchtest now covers repeated and overlapping intervals, invalid intervals, keyword arguments, callbacks that modify their input, and list/tuple subclasses. The FASTA tests pass, both normally and under ASan/UBSan.