Kryonet Optimization With #sendTCP()

  1. Simple question: are these two calls sending the same amount of bytes?

… and for my sanity…
2) If no to question #1, what is the size of a ‘new IntTest()’
3) If no to question #1, what is the size of a ‘new ByteTest()’

sendTCP(new ByteTest()); // #1
sendTCP(new IntTest());  // #2
public class ByteTest() {
    byte b;
}
public class IntTest() {
    int i;
}

My understanding of Kryonet is as follows: both objects are being converted into respective byte arrays and then pushed onto an output byte array buffer(?) so it would make logical sense that the ByteTest object would be smaller on the output buffer than the object IntTest simply because an int requires 4 times the amount of bytes.

Assuming the previous sentence is true, I’ve been reading posts on SO that claim ‘there is no point’ to this ‘optimization’… but I find that statement hard to believe if bandwidth is a bottleneck, which then justifies thorough optimizations of this nature within the architecture.

AFAIK KryoNet doesn’t look at the primitive type, but at the value: a byte with the value 0 would take as much space as a long with the value 0. A long with a large value would take more bytes.

sendTCP(new ByteTest()); // #1
sendTCP(new IntTest());  // #2

This sends:


varint (ByteTest class ID)
byte (ByteTest#b)
varint (IntTest class ID)
varint (IntTest#i)

Probably the class IDs are 1 byte, unless you register > 64 classes. IntTest#i is 1 byte for -64 to 64, etc. Larger ints use more bytes. You can also adjust the varint to be 1 byte from 0 to 128, eg if you knew it should never be negative.

Your two sends use 4+ bytes. There is no point optimizing this. Any send < the MTU size (~1400) is likely sent in a single packet anyway.

One of the debugging modes (either debug or trace, I don’t remember) allows you to see how many bytes each send is