From a79d5d8ef0b986f0b4b6ac631e71bd4eb0c1f802 Mon Sep 17 00:00:00 2001 From: Ben Reeves Date: Tue, 18 Jan 2022 00:45:21 -0600 Subject: [PATCH] Box up all Packet variants. Previously, the Packet enum was a whopping 4,264 bytes in size (over a page!). Not only is this just bad for performance (lots of memmoving), but I think it was also causing weird stack overflow segfaults on my machine. --- protocol/src/protocol/mod.rs | 4 ++-- src/server/mod.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 44d5017a..9c9d81b0 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -84,7 +84,7 @@ macro_rules! state_packets { $( $( $( - $name($state::$dir::$name), + $name(Box<$state::$dir::$name>), )* )+ )+ @@ -184,7 +184,7 @@ macro_rules! state_packets { packet.$field = Serializable::read_from(&mut buf)?; } )+ - Result::Ok(Option::Some(Packet::$name(packet))) + Result::Ok(Option::Some(Packet::$name(Box::new(packet)))) }, )* _ => Result::Ok(Option::None) diff --git a/src/server/mod.rs b/src/server/mod.rs index 1851e9b1..1dd5d192 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -98,7 +98,7 @@ macro_rules! handle_packet { }) => ( match $pck { $( - protocol::packet::Packet::$packet(val) => $s.$func(val), + protocol::packet::Packet::$packet(val) => $s.$func(*val), )* _ => {}, }