Lower traffic when I convert a float into a short?

Options
Hi,

I made some tests to see if I can reduce server traffic. But I guess you have already optimized your internal code and this is not necessary on my side.

Stats:
-> with short: average is 172 packet bytes, 158 command bytes
-> with float: average is 184 packet bytes, 171 command bytes

I have programmed it as follow:
short:
stream.SendNext( (short) (myFloatValue*10000) );
myFloatValue = ((float) ((short)stream.ReceiveNext()) )/10000.0f;

float:
stream.SendNext( (float) (myFloatValue) );
myFloatValue = (float)stream.ReceiveNext();

When I use the short version, I have a little bit more cpu work, but lower network traffic.

I have found nothing in your manuals... so what do you suggest? Should I use the floats or the short values.
Klaus

Comments

  • Tobias
    Options
    Hard to tell if it makes sense.

    PUN is sending meta data with each OnPhotonSerializeView() which you can't skip. This would be more bytes than what you save now, if you can live without the extra info (which you can in many cases).
    If you really want to optimize things as much as possible, then you might even think about using PhotonNetwork.RaiseEvent(). This is the bare-metal way to send events and it's what PUN uses under the hood.

    A short is a few bytes less, yes. If you really care about the CPU work, then you should shift instead of using division and multiplication. It should not matter if shift ends up with multiplying by 1024 or if you do it with 1000 straight. Or do I miss something.
  • Thank you very much for explaining this. So I continue to use floats to keep the code clean.