perf(spectrum): build the backward RC query in a stack buffer - #33
Conversation
`mem_search_backward` allocated a fresh `Vec` for the reverse-complement query on every call (the consumer fires ~50 backward calls/read). Build it into a 256-byte stack buffer for the common read length instead, falling back to the heap only for reads longer than the buffer (e.g. long-read tech). No probe/result change — byte-identical (the `mem_search_backward_equals_maximal_backward_step` oracle proptest passes unchanged) — just removes the per-call heap allocation from the hot backward path. This is the exact `rc_stack`/`rc_heap` pattern already merged in `mem_search_backward_truncated_span_rc`/`_interval_rc` (#27/#30), applied to `mem_search_backward`'s RC build.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughIn ChangesReverse-complement memory allocation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
v0.3 perf series — PR-C (C-alloc), part 1 of the net-new alloc trims (the forward-routing commits are subsumed by #23's O(log) rewrite; see triage below).
What
mem_search_backwardbuilt a freshVec<u8>for the reverse-complement query on every call — and the consumer fires ~50 backward calls per read. This builds it into a 256-byte stack buffer for the common read length, falling back to the heap only for reads longer than the buffer.Byte-identical
Same
(b & 0x3) ^ 0x3bytes, sameq_key, sameforward_maximal_leninput — output unchanged. Guarded by the existingmem_search_backward_equals_maximal_backward_steporacle proptest (passes unchanged). Pure hot-path alloc removal.Why it's clean
This is the exact
rc_stack/rc_heappattern already merged inmem_search_backward_truncated_span_rc(#27) and_interval_rc(#30) —mem_search_backwardwas the one RC-build path that still allocated. So it's also a sibling-consistency fix: the three RC-build sites now match.PR-C triage (recorded for the series)
The carving plan flagged PR-C (forward micro-opts) as needing a triage vs merged #23. Result:
mem_search; perf: O(log) cold one-shot maximal exact match (forward + backward) #23's rewrite already does that work),2efa208(THP for the .sa mmap — already merged as perf(sa): hint transparent huge pages for the .sa mmap (Linux) #25), and144632a(hoistkeyed_compare_mask— main's comparison path already hoists it;shares_prefix/ref_lessare 6-arg and don't take the mask).fa85f82) and17d506b(a combined position+keyentry()read — a separate follow-up).Pre-PR
/coderabbitai-review: 0 findings.Summary by CodeRabbit