From 0c9fbce63ae6e2c54f73c9ea8c0c4101a48c42c5 Mon Sep 17 00:00:00 2001 From: Petros Angelatos Date: Thu, 9 Mar 2023 21:54:25 +0100 Subject: [PATCH] session: only clone timestamps when needed In microbenchmarks (see https://github.com/MaterializeInc/materialize/pull/17998#discussion_r1131583050) the code in the PR performed better than the current version. Signed-off-by: Petros Angelatos --- timely/src/dataflow/channels/pushers/buffer.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/timely/src/dataflow/channels/pushers/buffer.rs b/timely/src/dataflow/channels/pushers/buffer.rs index 6f92dabb0..841bce02f 100644 --- a/timely/src/dataflow/channels/pushers/buffer.rs +++ b/timely/src/dataflow/channels/pushers/buffer.rs @@ -36,8 +36,13 @@ impl>> BufferCore where T: Eq /// Returns a `Session`, which accepts data to send at the associated time pub fn session(&mut self, time: &T) -> Session { - if let Some(true) = self.time.as_ref().map(|x| x != time) { self.flush(); } - self.time = Some(time.clone()); + match self.time { + Some(ref t) => if t != time { + self.flush(); + self.time = Some(time.clone()) + }, + None => self.time = Some(time.clone()), + }; Session { buffer: self } } /// Allocates a new `AutoflushSession` which flushes itself on drop.