Best Optimization Practices for C++ Performance

Hello everyone, I would like some hints/tips about good optimization practices to maintain a good C++ flow/performance, I’m quite new to C++ but not new to programming in general and this is why I know that there usually are some practices that allows for a better code performance, and since I’m on a quite decent-sized project now, I would like some tips to avoid performance issues in the long run, thank you very much.

I mean both, what to do and what NOT to do.

Parameter passing: CppCoreGuidelines/param-passing-normal.png at master · isocpp/CppCoreGuidelines · GitHub
The most important lesson there is that should should prevent copying of large objects (so try to prevent passing them by value).

Some general performance guidelines:

Besides that i think the UE4 code base makes it quity easy to write performant code. The available datastructures are good and i to my knowledge there no inefficient datastructures out there. Just pick the right one for your use case. My advise here is to build your own code based on their coding principles. Have a look at code that they implemented for a good idea how to keep it performant. For example: if you need a container class, always start with TArray and only use TMap/TSet when really needed (e.g. really large number of items in a container could make TMap/TSet faster)

If you are going to write multiplayer code another challenge is keeping the data send over the internet to a minimum.
You should try to prevent to many replicated properties and too many RPC calls. If you need to do it, try to do it with the smallest datastructure possible (boolean for example).

Ty man, happy to know that UE4 is quite simple to maintain a good performance, I think I’ll have no trouble with that !

One other advise: try prevent doing calculations in tick functions, these are done every frame. Instead try doing most calculations using events.

Just a note, I have reason to believe that bools actually get serialized as 32 bits, meaning you’d actually be better off just using an int8 or an enum