Skip to content

Commit 32a312f

Browse files
authored
Avoid reallocations in first keep, bound stash size (#430)
A follow-up to #425. Retain two elements instead of three in the stash. Avoid doubling reallocations in the first `keep` object. Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 615c688 commit 32a312f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/trace/implementations/merge_batcher_col.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,11 @@ where
105105
for datum @ ((_key, _val), time, _diff) in &buffer[..] {
106106
if upper.less_equal(time) {
107107
self.frontier.insert(time.clone());
108-
if !keep.is_empty() && keep.len() == keep.capacity() {
108+
if keep.is_empty() {
109+
if keep.capacity() != MergeSorterColumnation::<(U::Key, U::Val), U::Time, U::Diff>::buffer_size() {
110+
keep = self.sorter.empty();
111+
}
112+
} else if keep.len() == keep.capacity() {
109113
kept.push(keep);
110114
keep = self.sorter.empty();
111115
}
@@ -228,7 +232,7 @@ impl<D: Ord+Clone+Columnation+'static, T: Ord+Clone+Columnation+'static, R: Semi
228232

229233
/// Insert an empty buffer into the stash. Panics if the buffer is not empty.
230234
fn recycle(&mut self, mut buffer: TimelyStack<(D, T, R)>) {
231-
if buffer.capacity() == Self::buffer_size() && self.stash.len() <= 2 {
235+
if buffer.capacity() == Self::buffer_size() && self.stash.len() < 2 {
232236
buffer.clear();
233237
self.stash.push(buffer);
234238
}

0 commit comments

Comments
 (0)