Network Optimizations - Byte galore?

I recently learned about game optimization… Specifically network traffic. It seems to me that using bytes for EVERYTHING would be ideal…

Currently I have my server handle everything inventory related, but the client handles its UI. So, the client sends the server info when its using its inventory. Would it be better to send, say, a byte instead of an integer? Clearly it would be assuming you don’t need a value higher than 255. But what about other things, such as string? Could I send a byte(enum), and then convert it to a string on the server?

It seems as though it’s sending less data vs one less command the server needs to execute(albeit a small one - converting enum byte to string). Which is preferable? I could right now easily change essentially ALL of my variables to bytes. Should I? I would be very nice to learn which is preferable so I won’t have to make all of these optimizations in the future.

Also, how many bytes does a “2d texture” reference have? Or a “static mesh reference”? Is there some place I can find how many bytes every kind of variable has?

While making the code more efficient and faster, you are also making it unreadable for about 99% of the population on the planet and probably that much harder for yourself to track down an error if you were to use bytes. What you have to consider is if the trade-off is worth it, performance-wise.

As for the answer to your “2d texture” question… How much wood texture would a woodchuck choke on if a woodchuck could choke on wood textures?

If all you needed to send was a series of predefined messages, then yes, you could use bytes to specify what was sent and save some network traffic.

However, keep in mind that every packet has overhead, so if all you’re sending is a single byte in that packet, it’s still going to be huge. Just looked it up and UDP is 52 bytes for the header, and TCP is 64 bytes for the header. So if you’re trying to save 3 bytes on an INT by sending a BYTE instead, you probably shouldn’t knock yourself out trying.

However, if you were sending a lot of data in each packet (positions of many objects?), then slimming it down to 1/4 the size could be helpful indeed.

In short, don’t optimize too early. You might just be making it harder for yourself with little or no benefit.