Skip to content
Browse files

Override ReadByte in PacketReader.

Turns out, the normal BinaryReader was calling NetworkStream.ReadByte, which didn't override ReadByte. As such, every single call to ReadByte would wastefully allocate a 1 element byte array, which ended up being responsible for a significant portion of allocations when running server for extended periods of time.
  • Loading branch information...
UnknownShadow200 committed Aug 10, 2017
1 parent 215878e commit ebc445829f95f5ffdd61c727c81ba5bf332e998c
Showing with 8 additions and 1 deletion.
  1. +8 −1 fCraft/Network/PacketReader.cs
@@ -13,7 +13,14 @@ sealed class PacketReader : BinaryReader {
public OpCode ReadOpCode() {
return (OpCode)ReadByte();

byte[] oneBuffer = new byte[1];
public override byte ReadByte() {
int count = BaseStream.Read(oneBuffer, 0, 1);
if (count == -1) throw new EndOfStreamException("End of file");
return oneBuffer[0];

public override short ReadInt16() {
return IPAddress.NetworkToHostOrder( base.ReadInt16() );

0 comments on commit ebc4458

Please sign in to comment.
You can’t perform that action at this time.