Why use serialization/kryo at all?

Hi all,
i’m just about to implement multiplayer into my game and i have a hard time understanding the benefit of serialization / kryo which is recommended everywhere.
I’ve read several threads and from my understanding you serialize the entire java object and send it over the network.
But that just sounds like a HUGE waste of bandwidth. Don’t most games care about every little byte of bandwidth in case you want to support player hosted games?

What’s the benefit versus just sending everything as int/byte/etc. via DataOutputStream/Socket? Sure you need a custom write method for every class you want to send but that’s not much coding effort at all and doesn’t seem to justify the bandwidth overhead.

Do i miss something?

It’s easier and faster in most cases when you’re sending general data over the wire. Instead of fiddling with the bytes/ordering/rebuilding let kryo do it for you while it packs and compresses it giving you a nice Object to work with in the end. The size kryo actually sends over the wire is probably way, way less than any kind of “lite hack” you’d come up with anyway. Remember TCP comes with a lot of overhead anyway so sending a few bytes back and forth isn’t ideal.

kryo doesn’t write any unneeded class information, only what you need to replicate the object (if you register it with an id!).
so if you register and serialize an object which has two float fields, kryo will write an id and the two floats, and not much more than that.

But you are right that serializing huge and deep object graphs has an overhead for writing the object ids, which is wasteful, so best practice is to only write shallow objects for less overhead or you write your own serializer to optimize your specific case.