From 62e0b53f5255534b346287bcff2e2f3e21ef2e94 Mon Sep 17 00:00:00 2001 From: timedout Date: Mon, 29 Jun 2026 19:07:28 +0100 Subject: [PATCH] feat: Prioritise sending dummy events when the extremity count reaches 20 or more --- src/service/rooms/event_handler/handle_incoming_pdu.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/service/rooms/event_handler/handle_incoming_pdu.rs b/src/service/rooms/event_handler/handle_incoming_pdu.rs index 63b7f71d8..f9a497f3c 100644 --- a/src/service/rooms/event_handler/handle_incoming_pdu.rs +++ b/src/service/rooms/event_handler/handle_incoming_pdu.rs @@ -351,8 +351,14 @@ impl super::Service { if let Some((extremities_count, is_dummy_event)) = msg { latest_extremity_count = Some(extremities_count); non_dummy_event = non_dummy_event || !is_dummy_event; + let sleep_duration = if extremities_count >= 20 { + // Skip the original sleep duration and send in the next 3-7 seconds as the number of extremities has grown beyond what one squash can reasonably reduce. We still jitter here in case we receive more events in that time that reduce the number anyway, and to account for other servers sending the same squashes. + jitter(Duration::from_secs(5), -50.0..=50.0) + } else { + jitter(Duration::from_mins(1), -50.0..=50.0) + }; #[allow(clippy::arithmetic_side_effects)] - waker.as_mut().reset(tokio::time::Instant::now() + jitter(Duration::from_mins(1), -50.0..=50.0)); + waker.as_mut().reset(tokio::time::Instant::now() + sleep_duration); } else { {let mut map = service.extremity_squashers.write(); if let Some(tx) = map.get(&room_id) && tx.is_closed() {