Broad question, very hard to answer in a way that will make sense to someone just starting. Either way, these things help, but are only a partial list:
Straight-line code with no virtual dispatch (e.g. calls to methods that can be overloaded). You can avoid this for simple cases with conditionals, and more complex ones by sorting the data ahead of time so that you know what to call. (Better than either of these is to organize your program so that you would never need to do this in the first place.)
No dynamic allocation that can be avoided. Definitely no calls to system malloc/free. Heavy use of arenas and (compacted) pools.
Struct of arrays and not arrays of structs (instead of having an array of an object that has N fields, each field has its own array, so you have N arrays. Additionally, you make sure these are all allocated from the same slab)
Lots of others.
Honestly I think the code is cleaner without OO, and am sort of annoyed at it being called spaghetti code, although I liked OO when I started.
For what it's worth this is NOT the reason that CryTek is bad.
Basically it's a balance between processing efficiency and dev time efficiency. A lot of convenient abstractions like OO tend to cause your compiled code to have to do things that aren't very efficient.
As a very crude and probably slightly incorrect example: Let's say you have objects that, when you use a method of them, need to grab a resource, do something with it, and then close/drop the resource. So object.do_thing() compiles down to something like
Side note though: this isn't at all specific to OO, it's more a symptom of any type of abstraction (which includes OO). That said, it's a fuck-ton faster for you to write and most of the time, computers are fast enough that it's just not worth your time to write it in a more efficient way. Also, modern compilers are really really good at fixing all this shit FOR you.
You could check out this article. Not saying it's necessarily the best way to go, but the ideas generally will give you better performance than having a bunch of objects flopping around in RAM.
1
u/[deleted] Jan 25 '15
Can you explain to me what architecture is the most efficient? I'm just starting to learn my first OO language. Thanks.