I've been running around the code looking for opportunities to optimize.
RPCs are functions that are called over the network. For example, when the player shoots, it calls an RPC on the server which shoots. Previously, finding and calling the command was done with reflection. This worked, and is reasonably fast, but it creates allocations. So the very fast way would be to have a function that would say "if we want to call this function, call it". That'd be a hard thing to do by hand, so I made a code generator that generates this code for us. Now the RPC calls are now as fast as they could possibly be, and totally allocation free.
We had a variable reference script on our HUD. Instead of the code saying "if player health changed, update this text", we can set that up in the editor, which uses reflection to find a variable to latch on to. This is awesome and makes things easy, but it isn't fast, and every call was allocating about 20b. So I got rid of it in all our code and coded it the fast way, saving us about 0.2ms every frame.
When you look at something in the game it shows a menu, depending on what you're looking at. These menus are defined in the code using attributes, and are looked up using reflection. This is slower than it has to be and was causing a ton of allocations. I used the RPC code generator to convert this to the same kind of flat system.
I also fixed a pretty large allocation in the player tick. This was a bug in the code generated by our
proto system. It was a small but consistent allocation.
So the main client loop is allocation free now. This adds up to less stutters and memory usage, overall if you have a decent computer it's debatable whether you'll see any benefit, but it all adds up.
We still have work to do in other areas, so I'm going to continue down this path for another week to see if I can speed things up.