From 6ade20fdad799e73516a5f50e38aa79e51de5266 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20CORTIER?= Date: Wed, 5 Aug 2026 16:41:47 +0900 Subject: [PATCH] perf(jmux): reuse sender flush timer Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- crates/jmux-proxy/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/jmux-proxy/src/lib.rs b/crates/jmux-proxy/src/lib.rs index ef27258f1..7373fce85 100644 --- a/crates/jmux-proxy/src/lib.rs +++ b/crates/jmux-proxy/src/lib.rs @@ -41,6 +41,7 @@ pub use self::event::{EventOutcome, TrafficEvent, TransportProtocol}; const MAXIMUM_PACKET_SIZE_IN_BYTES: u16 = 4 * 1024; // 4 kiB const WINDOW_ADJUSTMENT_THRESHOLD: u32 = 4 * 1024; // 4 kiB +const JMUX_FLUSH_DELAY: core::time::Duration = core::time::Duration::from_millis(10); // The JMUX channel will require at most `MAXIMUM_PACKET_SIZE_IN_BYTES × JMUX_MESSAGE_CHANNEL_SIZE` bytes to be kept alive. const JMUX_MESSAGE_MPSC_CHANNEL_SIZE: usize = 512; @@ -384,6 +385,8 @@ impl JmuxSenderTask { let mut jmux_writer = tokio::io::BufWriter::with_capacity(16 * 1024, jmux_writer); let mut buf = bytes::BytesMut::new(); let mut needs_flush = false; + let flush_timer = tokio::time::sleep(JMUX_FLUSH_DELAY); + tokio::pin!(flush_timer); loop { tokio::select! { @@ -399,8 +402,9 @@ impl JmuxSenderTask { jmux_writer.write_all(&buf).await?; needs_flush = true; + flush_timer.as_mut().reset(tokio::time::Instant::now() + JMUX_FLUSH_DELAY); } - _ = tokio::time::sleep(core::time::Duration::from_millis(10)), if needs_flush => { + _ = flush_timer.as_mut(), if needs_flush => { jmux_writer.flush().await?; needs_flush = false; }