Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion timely/src/progress/change_batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,11 @@ where
#[inline]
pub fn compact(&mut self) {
if self.clean < self.updates.len() && self.updates.len() > 1 {
self.updates.sort_unstable_by(|x,y| x.0.cmp(&y.0));
// A stable sort, not `sort_unstable_by`: `updates[..clean]` is already sorted, and
// the stable sort finds that run and merges the new updates into it in linear time,
// where the unstable sort sorts the whole list again. It allocates scratch only past
// its stack buffer (4 KiB), so a small batch still allocates nothing.
self.updates.sort_by(|x,y| x.0.cmp(&y.0));
for i in 0 .. self.updates.len() - 1 {
if self.updates[i].0 == self.updates[i+1].0 {
self.updates[i+1].1 += self.updates[i].1;
Expand Down