From 50f0dcb4dd96aff8ac87c40a3d80bbdd74763741 Mon Sep 17 00:00:00 2001 From: Nils Andreas Svee Date: Fri, 17 Jul 2026 11:39:07 +0700 Subject: [PATCH] perf(baseliner): bound the reselection channel to prevent memory buildup Change the reselection channel from unbounded to a size of 1 and use non-blocking sends to avoid unnecessary queuing of reselection triggers. --- src/baseliner.rs | 6 +++--- src/main.rs | 2 +- src/ratecontroller.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/baseliner.rs b/src/baseliner.rs index 041f78f..b32ec47 100644 --- a/src/baseliner.rs +++ b/src/baseliner.rs @@ -122,9 +122,9 @@ impl Baseliner { reflector: Some(time_data.reflector), tags: &[], }); - // If reselection is disabled this would trigger an error - // so just ignore the result - let _ = self.reselect_trigger.send(true); + // The reselect channel is bounded to 1, + // so we use try_send to avoid blocking if the channel is full + let _ = self.reselect_trigger.try_send(true); } else { owd_baseline.down_ewma = owd_baseline.down_ewma * slow_factor + (1.0 - slow_factor) * time_data.down_time; diff --git a/src/main.rs b/src/main.rs index 862413b..7a85833 100644 --- a/src/main.rs +++ b/src/main.rs @@ -265,7 +265,7 @@ fn run(config: Config) -> anyhow::Result<()> { let (baseliner_stats_tx, baseliner_stats_rx) = flume::unbounded(); let (error_tx, error_rx) = flume::unbounded::(); - let (reselect_tx, reselect_rx) = flume::unbounded(); + let (reselect_tx, reselect_rx) = flume::bounded(1); let dropped = Arc::new(AtomicU32::new(0)); diff --git a/src/ratecontroller.rs b/src/ratecontroller.rs index 096d190..32ecc61 100644 --- a/src/ratecontroller.rs +++ b/src/ratecontroller.rs @@ -308,7 +308,7 @@ impl Ratecontroller { state_dl.deltas.len(), state_ul.deltas.len() ); - let _ = self.reselect_trigger.send(true); + let _ = self.reselect_trigger.try_send(true); } Ok(())