Skip to content

Commit a79d5d8

Browse files
committed
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.
1 parent 9fca022 commit a79d5d8

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

protocol/src/protocol/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ macro_rules! state_packets {
8484
$(
8585
$(
8686
$(
87-
$name($state::$dir::$name),
87+
$name(Box<$state::$dir::$name>),
8888
)*
8989
)+
9090
)+
@@ -184,7 +184,7 @@ macro_rules! state_packets {
184184
packet.$field = Serializable::read_from(&mut buf)?;
185185
}
186186
)+
187-
Result::Ok(Option::Some(Packet::$name(packet)))
187+
Result::Ok(Option::Some(Packet::$name(Box::new(packet))))
188188
},
189189
)*
190190
_ => Result::Ok(Option::None)

src/server/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ macro_rules! handle_packet {
9898
}) => (
9999
match $pck {
100100
$(
101-
protocol::packet::Packet::$packet(val) => $s.$func(val),
101+
protocol::packet::Packet::$packet(val) => $s.$func(*val),
102102
)*
103103
_ => {},
104104
}

0 commit comments

Comments
 (0)