[QDP] StreamingProducer: use VecDeque for O(1) buffer advance - #1462
[QDP] StreamingProducer: use VecDeque for O(1) buffer advance#14620lai0 wants to merge 2 commits into
Conversation
viiccwen
left a comment
There was a problem hiding this comment.
Thx for the correctness and capacity tests. Since the main change is hot-path performance, could you also provide a small reproducible before/after benchmark?
It would be helpful to compare the current Vec + cursor implementation against this VecDeque implementation.
|
LGTM. |
|
Thanks @viiccwen and @rich7420 Buffer-only (refill chunk 65536), Xeon w3-2435,
E2E via Parquet: ~1.01–1.02x (decode dominates). Win only when batch ≪ chunk; at 1:1+ both do the same work. |
There was a problem hiding this comment.
we don't need to expose any benchmark experiment in command.
Related Issues
Closes #1436
Changes
Why
StreamingProducertracked consumed elements with abuffer_cursorand, once the cursor passed the halfway mark (BUFFER_COMPACT_DENOM), reclaimed the prefix withVec::drain(..cursor)— an O(n) memmove of the retained tail, on the streaming hot path.A
VecDequeadvances its head instead, so discarding a consumed prefix never shifts the data that is still live: O(1) amortized buffer advance, no periodic compaction pass, and no change in output.How
buffer: Vec<T>+buffer_cursor: usize→buffer: VecDeque<T>; removed the now-unusedBUFFER_COMPACT_DENOMcompaction heuristicproduce()copies the batch out ofas_slices()(stitching both halves when a batch straddles the ring's wrap boundary), thendrain(..take)s the consumed prefix. Copying via the slices keeps the batch copy onextend_from_slice's bulk path —Drainis notTrustedLen, soextend(drain)would copy element by element. Recycled batch buffers are still reused, so the batch copy itself stays allocation-freeextend(&scratch[..written])rather than.iter().copied():VecDequespecializesExtend<&T> for T: Copyinto a bulkcopy_slicebatch_size * sample_size + initial_cap, the peak live length) so the ring never reallocates mid-run.VecDeque::from(Vec)reuses the existing allocation, so this only tops the capacity up.Checklist