From 61d1c276058f64435f71f6140fbcf6293cef5864 Mon Sep 17 00:00:00 2001 From: Joshua Yanovski Date: Thu, 7 Jul 2022 22:00:45 -0700 Subject: [PATCH] Spawn fewer slowjob tasks. --- client/src/lib.rs | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/client/src/lib.rs b/client/src/lib.rs index 6cb1681943..b022b0d530 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -2415,21 +2415,30 @@ impl Client { } self.handle_server_in_game_msg(frontend_events, bincode::deserialize(&msg.decompress()?)?)?; } + + // Batch up terrain updates for deserialization. + let mut terrain_messages = Vec::new(); while let Some(msg) = self.terrain_stream.try_recv_raw()? { - cnt += 1; + terrain_messages.push(msg); + } + if !terrain_messages.is_empty() { + cnt += terrain_messages.len() as u64; let terrain_tx = self.terrain_tx.clone(); self .state .slow_job_pool() .spawn("TERRAIN_DESERIALIZING", move || { - let handle_msg = || { - let msg = msg.decompress()?; - let msg = bincode::deserialize(&msg)?; - Self::handle_server_terrain_msg(msg) - }; - terrain_tx.send(handle_msg()); + terrain_messages.into_iter().for_each(|msg| { + let handle_msg = || { + let msg = msg.decompress()?; + let msg = bincode::deserialize(&msg)?; + Self::handle_server_terrain_msg(msg) + }; + terrain_tx.send(handle_msg()); + }); }); } + while let Ok(msg) = self.terrain_rx.try_recv() { let msg = msg?; #[cfg(feature = "tracy")]