How does game “optimization” work? Are people sitting there changing lines of code to more “optimal” ones? What is “optimized”?

2.07K views

The recent The Last of Us for PC made me realize I had no idea what’s meant by “optimizing” a game.

Same with optifine in Minecraft improving performance. How do these things work to just make games use fewer resources?

In: 158

105 Answers

Anonymous 0 Comments

Most of the other explanations go over general software and game optimizations, which are (or should be) already routinely performed by the software developers working on the lower layers of the game engine. Whilst this is related to what you’re trying to get at, it’s only half of the picture.
The other half is the fact that the technology stack down to the hardware which the game was originally intended to run on, and the one it eventually gets ported to, can be considerably different. Add to that the fact that the hardware in the PC is a diverse set of parts rather than just 1 configuration.
This is why games need optimizations for a given platform, by which we mean the accounting of these differences by the game developers such that swapping the platform is, at the very least, unnoticeable, experience-wise. As you can tell from the history of PC ports, it’s a complicated problem to tackle.

Anonymous 0 Comments

Optimisation can mean many things. It is just general term. However lets visualise it like this:

How would you simplify 4×7? Well… I was taught to memorise the tables. That is actually a form of optimisation. There is no point calculating it if you can just have table with already calculated solutions. So you can have a table of 10×10 solutions, and look it up there. However 7+7+7+7 as a cumulative method is an easy way to do it also.

So lets imagine you have items in your game with special multipliers, and then stats with special multipliers. Every time you swing your weapon in the game you can do two things: calculate the result, or look up the result. Depending on situation, either can be more optimal. than the other. If you know that you have a dagger with +1 damage, and enemy with -1 to dagger damage. You don’t need to do the maths in-game to solve this. You can have a table to refrence against, and no need to do pointless “Damage +1 -1” maths. This is how it was done on table top. However if you work with percents, your tables can grow really big an burdensome, so calculating it might more efficient.

For optimisation of the graphics, there is an art to it. Quite literally. To turn high polygon detailed model in to one with few hundred, and then simplifying the textures and using maps to pre-calculate effects, lights, and light. This is done by hand, because it requires actual aesthetic choices. If your game has sharp style and very little rounded surfaces. Well you could sacriface detal of roundness, but not of sharp geometry. **Unless** you want to make something stand out by being clearly more rounded. Same thing happens with compression of textures, if you have very little red… it could be more optimal to just disregard that red. If you want something to be really bright against warm colours… Well… You don’t need to add range of contrast or brightness, add cold colours to make contrast stand out as bright. This way you can clamp the ranges, and get an effect of brightness.

For the gameworlds itself. Lots of optimisation is actually done by precalculating things. Go play Portal 2, and turn on the narration bits. In the intro they explain how they were able to achieve that collapse of the walls and the pod you are in, that would have taken lot of work to calculate real time. Well the joke is that they calculated it all real time. The game doesn’t calculate the physics at all on the props. This would been quite feat to do properly for 2011 hardware, and not have it do the “jiggles” and have parts flying to the moon from collisions.

Same thing with lights, reflections and shadows. If you know that a light will always come from on direction and the scene is static. You don’t need to calculate the shadows, you don’t even need to have that light “for real”. You can just precompute it all, and project the shadows and even lights. Suddenly a act of rendering light and shadows, is just a simple task of projecting shapes. Something that computers and game engines are really good.

Same applies for something that is just 2D. If you need something to just be 2D thing and animate. No need for video files or animation frames. Just make a animated sprite of it. You can actually make a cobblestone street and now need more than 2 polygons and have realistic results. Why? Just precalculate the whole thing and have it as maps and tectures. You have turned massive amount of geometry in a simple picture that tells the computer to show things in special way.

Anonymous 0 Comments

Most of the other explanations go over general software and game optimizations, which are (or should be) already routinely performed by the software developers working on the lower layers of the game engine. Whilst this is related to what you’re trying to get at, it’s only half of the picture.
The other half is the fact that the technology stack down to the hardware which the game was originally intended to run on, and the one it eventually gets ported to, can be considerably different. Add to that the fact that the hardware in the PC is a diverse set of parts rather than just 1 configuration.
This is why games need optimizations for a given platform, by which we mean the accounting of these differences by the game developers such that swapping the platform is, at the very least, unnoticeable, experience-wise. As you can tell from the history of PC ports, it’s a complicated problem to tackle.

Anonymous 0 Comments

Coding is just telling the computer to do stuff. Optimizing is going into more and more detail, being very specific, do this in this very specific way, ignore that, load this while calculating that, get rid of this NOW, show this but not that, instead of just letting the computer do it in some easily understood way, no matter how long it’ll take, and how many resources it might take.

It’s trading human time and effort for computers doing stuff faster and using fewer resources.

In the specific case of the Last of Us, the game was already optimized for a different type of computer, and what works for one might be a dumb decision for another.

Anonymous 0 Comments

“optimized” (as an example) is loading the same skin texture for separate assets just once (instead of loading it each time for each asset.)

and then making sure that you really need to load 18,000 different textures instead of, maybe, 500 or so.

Anonymous 0 Comments

Coding is just telling the computer to do stuff. Optimizing is going into more and more detail, being very specific, do this in this very specific way, ignore that, load this while calculating that, get rid of this NOW, show this but not that, instead of just letting the computer do it in some easily understood way, no matter how long it’ll take, and how many resources it might take.

It’s trading human time and effort for computers doing stuff faster and using fewer resources.

In the specific case of the Last of Us, the game was already optimized for a different type of computer, and what works for one might be a dumb decision for another.

Anonymous 0 Comments

algorithmic problems (programming) can be solved in a number of ways, to achieve the same result. some run faster, some run slower. this is direct consequence of how the silicone is built and organized. say, you perform an operation using one complicated instruction, that takes many CPU cycles to complete. BUT – you can achieve the same result by breaking it down into more steps, that in total will run *faster* that the single, complicated instruction. this is more/less what code optimization is.

p.s. this is also the reason why CPU realm is divided into two contradictory approaches. ever heard of [RISC](https://en.wikipedia.org/wiki/Reduced_instruction_set_computer) vs. [CISC](https://en.wikipedia.org/wiki/Complex_instruction_set_computer)? this is exactly the same problem, but in context of silicon design and code execution approach. either one complex instruction to do something, or set of simple instructions to do exactly the same thing, but differently.

Anonymous 0 Comments

Coding is just telling the computer to do stuff. Optimizing is going into more and more detail, being very specific, do this in this very specific way, ignore that, load this while calculating that, get rid of this NOW, show this but not that, instead of just letting the computer do it in some easily understood way, no matter how long it’ll take, and how many resources it might take.

It’s trading human time and effort for computers doing stuff faster and using fewer resources.

In the specific case of the Last of Us, the game was already optimized for a different type of computer, and what works for one might be a dumb decision for another.

Anonymous 0 Comments

“optimized” (as an example) is loading the same skin texture for separate assets just once (instead of loading it each time for each asset.)

and then making sure that you really need to load 18,000 different textures instead of, maybe, 500 or so.

Anonymous 0 Comments

“Optimisation” is a blanket term that encompasses a wide array of techniques and practises whose aim is to make code as efficient as possible, or in other words, requiring the least amount of resources from a system (processing power, memory etc) while producing the same result. The main reason this is desirable is because it enables developers to either make the most out of a given system (i.e. a gaming console with fixed specs) or because it enables a PC game to reach a wider audience if it has low system requirements.

There’s many methods this is achieved through. The basic form of optimising code is much like simplification in math. Lines of code can be simplified and made shorter which in turn reduces the amount of data. Code can also be made more efficient in the way it utilises the system resources. Data can be compressed, clever ways of loading and unloading can be utilised, unecessary processes can be deleted etc.