From 3e1d1035144eba340fe29c1cc1d176cb4cafc367 Mon Sep 17 00:00:00 2001 From: lukas0008 Date: Sun, 18 Aug 2024 18:40:38 +0200 Subject: [PATCH] Slightly improve performance - Only try to decode packet when new data arrives. --- pumpkin/src/client/mod.rs | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pumpkin/src/client/mod.rs b/pumpkin/src/client/mod.rs index 01314a9c6..1389a535c 100644 --- a/pumpkin/src/client/mod.rs +++ b/pumpkin/src/client/mod.rs @@ -385,23 +385,28 @@ impl Client { self.kick(&e.to_string()).await; break; } + }; + loop { + match self.dec.decode() { + Ok(Some(packet)) => { + self.add_packet(packet); + let mut server = server.write().await; + self.process_packets(&mut server).await; + continue; + } + Ok(None) => break, + Err(err) => { + self.kick(&err.to_string()).await; + break; + }, + }; } + }, _ = tokio::time::sleep(Duration::from_millis(100)) => { // Handle timeout (optional) } } - - match self.dec.decode() { - Ok(packet) => { - if let Some(packet) = packet { - self.add_packet(packet); - let mut server = server.write().await; - self.process_packets(&mut server).await; - } - } - Err(err) => self.kick(&err.to_string()).await, - } } }