Fabric API

Fabric API

108M Downloads

[Enhancement] Serialize custom packet in networking thread instead of the client/server thread

qouteall opened this issue ยท 2 comments

commented

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.

https://github.com/FabricMC/fabric/blob/1.20.2/fabric-networking-api-v1/src/main/java/net/fabricmc/fabric/impl/networking/server/ServerNetworkingImpl.java#L66C21-L66C21

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.

commented

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.

commented

it failed.

Not really, it turned out to me more work than I originally expected, so decided to leave it for a later date. Its totally possible to do without breaking the current API.