From c72a15743157c69cf9469e41b9ef62ad793f59ad Mon Sep 17 00:00:00 2001 From: Frank McSherry Date: Fri, 12 Jun 2026 16:08:39 -0400 Subject: [PATCH] builder_rc: trim bookkeeping vector capacities at build Pushing into initially empty vectors reserves capacity four; the frontier, consumed, internal, and produced vectors hold one element per port and live as long as the operator. The trade is one reallocation per vector at build time for proportionate memory thereafter. Co-Authored-By: Claude Fable 5 --- timely/src/dataflow/operators/generic/builder_rc.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/timely/src/dataflow/operators/generic/builder_rc.rs b/timely/src/dataflow/operators/generic/builder_rc.rs index 1c9d809f2..dcbe169a1 100644 --- a/timely/src/dataflow/operators/generic/builder_rc.rs +++ b/timely/src/dataflow/operators/generic/builder_rc.rs @@ -183,6 +183,15 @@ impl<'scope, T: Timestamp> OperatorBuilder<'scope, T> { let mut logic = constructor(self.mint_capabilities()); + // These vectors grew by `push` from empty, reserving capacity four; ports + // are few and the vectors live as long as the operator, so trim the excess. + // The trade is one reallocation per vector at build time for memory + // proportional to ports, rather than capacity, thereafter. + self.frontier.shrink_to_fit(); + self.consumed.shrink_to_fit(); + self.produced.shrink_to_fit(); + self.internal.borrow_mut().shrink_to_fit(); + let mut bookkeeping = ProgressBookkeeping { frontier: self.frontier, consumed: self.consumed,