[Enhancement] Serialize custom packet in networking thread instead of the client/server thread
qouteall opened this issue ยท 2 comments
Currently, for the new object-based networking API, when creating the packet, it serializes the packet in the clinet/server main thread. Vanilla packets are serialized on networking thread. If the packet is large, moving the serialization to networking thread could improve performance. What's more, in singleplayer, the packet objects are passed by object reference, not serialized or deserialized, to improve performance, so it could also improve performance for singleplayer case.
The payload object carries PacketByteBuf
. It's possible to make it to carry the packet object instead of buffer. https://github.com/FabricMC/fabric/blob/1.20.2/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/payload/PacketByteBufPayload.java
This cannot be done to the old networking API because it accepts the PacketByteBuf
as argument.
Currently the new networking API is just a wrapper of the old one. We'll need to change the code there. And yes, @modmuss50 did try this during snapshot cycle, it failed.