Repository navigation
perf(sort): reuse buffers in merge phase via producer-consumer buffer pool - #219
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #219 +/- ##
==========================================
- Coverage 88.07% 88.06% -0.02%
==========================================
Files 113 113
Lines 52863 52804 -59
==========================================
- Hits 46561 46503 -58
+ Misses 6302 6301 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📝 WalkthroughWalkthroughThe 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/lib/sort/raw.rs`:
- Around line 423-431: The implementation of next_record(&mut self, buf: &mut
Vec<u8>) only swaps vectors but doesn't enable real buffer reuse because
producers allocate fresh Vec<u8> per record (see read_records) and consumed
caller buffers get dropped/parked (forward-only memory source using idx); to
fix, change the producer APIs (e.g., read_records and any producer filling the
channel used by receiver) to write into caller-owned buffers or to return empty
buffers back into a reusable pool instead of allocating new Vecs, and update the
receiver/next_record code to accept and forward these pooled/filled buffers
(keep symbols: next_record, receiver.recv, read_records, idx) so that the
swapped-out buffer is reused by the producer rather than dropped.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 59d722a7-eba7-4fcb-92dc-bca87002d67e
📒 Files selected for processing (1)
src/lib/sort/raw.rs
Change GenericKeyedChunkReader::next_record and all ChunkSource wrappers to accept a &mut Vec<u8> buffer parameter instead of returning an owned Vec<u8>. This lets merge loops write directly from each heap entry's buffer and refill it in-place, avoiding per-record Vec allocations and the intermediate output_buffer that previously collected owned Vecs before flushing.
f20deba to
9ac7632
Compare
Summary
GenericKeyedChunkReaderso the consumercan return spent
Vec<u8>buffers to the producer thread for reuse. Theproducer calls
try_recv(non-blocking) to grab a recycled buffer beforeeach record read, falling back to a fresh allocation only when the pool is
empty. This eliminates per-record heap allocation in the merge phase once the
pipeline warms up.
next_recordon allChunkSourcewrappers to accept a&mut Vec<u8>buffer parameter. Merge loops now write directly from each heap entry's record
buffer and refill it in-place.
output_buffer: Vec<Vec<u8>>batching layer thatpreviously collected 2048 owned
Vecs before flushing.indexed merge.
Test plan
cargo ci-fmtpassescargo ci-lintpassescargo nextest run --no-fail-fast— all 1735 tests pass