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

1.98K 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

A well documented article about someone actually doing the hard work outside of the dev team itself:

https://nee.lv/2021/02/28/How-I-cut-GTA-Online-loading-times-by-70/

Anonymous 0 Comments

>Are people sitting there changing lines of code to more “optimal” ones?

in eli5: yes, they replace one way of doing things with a more opptimal one

there are many ways you can optimize games, like replacing how you store, process and access data, removing/remodeling procedures which slow down (bottleneck) the rest of your code, redesign processes so you can distribute it across multiple threads

Anonymous 0 Comments

Let’s say you have 100 pieces of Lego and you want to sort them by size.

So the easy solution is to pick the smallest one and set it to the side. Then you pick the next smallest one and put it right to the first, and so on.

That’s easy, but takes quite a while because you always have to check which one is actually the smallest.

One optimization would be to just make rough piles first. All the small pieces in one pile, all the medium ones in another and one for large piles. That’s quick to do and now you have way smaller piles you can sort by size. You can repeat this process again and have even smaller piles, so in each pile it will be easy to see which one is actually the smallest.

That’s basically the quicksort algorithm, which is way faster than the selection sort we used in the beginning.

Optimization is about finding better ways to approach problems. Another example is finding an element in a list, pathfinding, collision detection, etc – for all those things you can write simple algorithms that are slow, or better and faster algorithms that are usually more complicated to figure out.

Anonymous 0 Comments

Computers are only really good at a few specific operations and tasks like adding, subtracting, comparing, and stuff like that because, when you get down to it, a computer only has the basic logic gates (AND, OR, XOR, NOR, NOT).

Now, you might notice that that is actually a really short list, so anything else has to be a combination of those simpler operations in some specific order. As an example, when a computer wants to multiply numbers it has a few tricks to accomplish that be doing a bunch of addition. The whole field of computer science is really just figuring out ways of combining those operations to do other things.

My go to example for explaining optimization with computers is sorting: you have a large number of index cards with numbers on them and want to put them in assending order, how optimized your method is can be measured by how many times you compare two cards with fewer being better. The worst of the basic implementations is called “Bubble Sort” which essentially finds the biggest number, removes it, and then repeats until the original pile is empty.

With software the go to methods of optimization are:

Do more than one thing at a time (Parallelization)

Don’t do things you don’t have to, especially if doing other things is important

When you have spare resources, use them to prepare the next area if possible

Design for the system that will run your software

That last one is the big problem for TLoU, what’s optimized for the PS2 and PS3 isn’t optimized for anything else and that’s a problem for making any kind of port between console and PC (Xbox less so because Microsoft has for the last few generations used very PC like hardware and software for the Xbox).

A fun video to check out if you want to see the extreme of this would be [this video by Stand Up Maths ](https://youtu.be/c33AZBnRHks), he goes into a bit of detail about how he made some slow code to answer a question and then several other people wrote more code that did the same thing faster and what their methods were.

Anonymous 0 Comments

Computers are only really good at a few specific operations and tasks like adding, subtracting, comparing, and stuff like that because, when you get down to it, a computer only has the basic logic gates (AND, OR, XOR, NOR, NOT).

Now, you might notice that that is actually a really short list, so anything else has to be a combination of those simpler operations in some specific order. As an example, when a computer wants to multiply numbers it has a few tricks to accomplish that be doing a bunch of addition. The whole field of computer science is really just figuring out ways of combining those operations to do other things.

My go to example for explaining optimization with computers is sorting: you have a large number of index cards with numbers on them and want to put them in assending order, how optimized your method is can be measured by how many times you compare two cards with fewer being better. The worst of the basic implementations is called “Bubble Sort” which essentially finds the biggest number, removes it, and then repeats until the original pile is empty.

With software the go to methods of optimization are:

Do more than one thing at a time (Parallelization)

Don’t do things you don’t have to, especially if doing other things is important

When you have spare resources, use them to prepare the next area if possible

Design for the system that will run your software

That last one is the big problem for TLoU, what’s optimized for the PS2 and PS3 isn’t optimized for anything else and that’s a problem for making any kind of port between console and PC (Xbox less so because Microsoft has for the last few generations used very PC like hardware and software for the Xbox).

A fun video to check out if you want to see the extreme of this would be [this video by Stand Up Maths ](https://youtu.be/c33AZBnRHks), he goes into a bit of detail about how he made some slow code to answer a question and then several other people wrote more code that did the same thing faster and what their methods were.

Anonymous 0 Comments

Let’s say you have 100 pieces of Lego and you want to sort them by size.

So the easy solution is to pick the smallest one and set it to the side. Then you pick the next smallest one and put it right to the first, and so on.

That’s easy, but takes quite a while because you always have to check which one is actually the smallest.

One optimization would be to just make rough piles first. All the small pieces in one pile, all the medium ones in another and one for large piles. That’s quick to do and now you have way smaller piles you can sort by size. You can repeat this process again and have even smaller piles, so in each pile it will be easy to see which one is actually the smallest.

That’s basically the quicksort algorithm, which is way faster than the selection sort we used in the beginning.

Optimization is about finding better ways to approach problems. Another example is finding an element in a list, pathfinding, collision detection, etc – for all those things you can write simple algorithms that are slow, or better and faster algorithms that are usually more complicated to figure out.

Anonymous 0 Comments

It’s hard to be specific because optimization revolves around knowing how your game specifically works, and then seeing where you can get rid of unnecessary work.

On the code side, it’s often a choice between speed and memory, so it only makes sense to make these changes once you know which ones you have excess of in certain areas of the game, and which one your running out of. You’ll also have a better idea of when you can “cache” data, i.e. process something once and reuse it later. The opposite is also true, if you’re running out of memory you might choose to stop caching data and just take a small performance hit in reprocessing the data, but try to time it for a point in the game where you can sacrifice a few FPS.

On the art side, once you know the models are locked in and aren’t going to be changing you can start merging them together (less individual models means they render faster) and other things that might screw up the workflow if you ever wanted to change them, but allows the computer to work with them better.

Anonymous 0 Comments

Computers are only really good at a few specific operations and tasks like adding, subtracting, comparing, and stuff like that because, when you get down to it, a computer only has the basic logic gates (AND, OR, XOR, NOR, NOT).

Now, you might notice that that is actually a really short list, so anything else has to be a combination of those simpler operations in some specific order. As an example, when a computer wants to multiply numbers it has a few tricks to accomplish that be doing a bunch of addition. The whole field of computer science is really just figuring out ways of combining those operations to do other things.

My go to example for explaining optimization with computers is sorting: you have a large number of index cards with numbers on them and want to put them in assending order, how optimized your method is can be measured by how many times you compare two cards with fewer being better. The worst of the basic implementations is called “Bubble Sort” which essentially finds the biggest number, removes it, and then repeats until the original pile is empty.

With software the go to methods of optimization are:

Do more than one thing at a time (Parallelization)

Don’t do things you don’t have to, especially if doing other things is important

When you have spare resources, use them to prepare the next area if possible

Design for the system that will run your software

That last one is the big problem for TLoU, what’s optimized for the PS2 and PS3 isn’t optimized for anything else and that’s a problem for making any kind of port between console and PC (Xbox less so because Microsoft has for the last few generations used very PC like hardware and software for the Xbox).

A fun video to check out if you want to see the extreme of this would be [this video by Stand Up Maths ](https://youtu.be/c33AZBnRHks), he goes into a bit of detail about how he made some slow code to answer a question and then several other people wrote more code that did the same thing faster and what their methods were.

Anonymous 0 Comments

Let’s say you have 100 pieces of Lego and you want to sort them by size.

So the easy solution is to pick the smallest one and set it to the side. Then you pick the next smallest one and put it right to the first, and so on.

That’s easy, but takes quite a while because you always have to check which one is actually the smallest.

One optimization would be to just make rough piles first. All the small pieces in one pile, all the medium ones in another and one for large piles. That’s quick to do and now you have way smaller piles you can sort by size. You can repeat this process again and have even smaller piles, so in each pile it will be easy to see which one is actually the smallest.

That’s basically the quicksort algorithm, which is way faster than the selection sort we used in the beginning.

Optimization is about finding better ways to approach problems. Another example is finding an element in a list, pathfinding, collision detection, etc – for all those things you can write simple algorithms that are slow, or better and faster algorithms that are usually more complicated to figure out.

Anonymous 0 Comments

the larger the code for something gets, the potential for unintended interactions increases exponentially. sometimes optimizing means to remove those unintended interactions, but sometimes you find ones that help and you then try to implement (“it’s not a bug, it’s a feature” type of thing). sometimes those unintended things are quirks of the language they are using, or for consoles if there is specific hardware the developers learn how to exploit as they gain experience. an example, in C++ the operation “i++” takes 2 or 3 processor cycles more than “++i”. a small amount to improve, but if you need i to count to a million, that’s 2-3 million processor cycles saved.