Optimize memory consumption by PacketEncoder