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

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

there are MANY ways to optimize things, but I’ll demonstrate a really simple example to make it clear what it means:

let’s say you are a PC technician. your company has a stack of 1000 laptops. they gave you a stack of 1000 pieces of paper that each have a different serial number on them. those are warranty cards. all of the laptops have a recall, and in order to send them in for free repair, you have to send each one in with their own warranty card with matching serial number in the box.

unoptimized code:

you power a laptop one. you manually look through all 1,000 pieces of paper to find the matching serial number. even after you find the serial number that matches it, you keep looking through the stack of warranty papers until you reach the end. even if the 1st page you check was the matching one. you still check the other 999 pages. you then put the warranty paper on the keyboard and close the lid to the laptop. put it in the completed pile, and grab the next laptop. repeat this for all 1000 laptops. since you have 1000 laptops and 1000 pieces of paper to check, it will be almost 1 MILLION times that you read the serial number on those cards. slow and inefficient

1st optimization:

you find out that only 100 of those laptops are new enough to get the fix. the others won’t be eligible. so you look on the bottom of each laptop and find the 100 that have the model number that IS eligible for the warranty fix. now we just cut our time down to 10% of what it was earlier, since we’re only checking 10% of the laptops.

2nd optimization:

humans aren’t this dumb, but computers programs by default will check ALL items in a list in a loop, unless you tell it to stop after it finds a match. so when you look through the warranty papers, as soon as you find a match, you put the paper on the keyboard, close the laptop, and put it in the done pile. if the 3rd paper you check is the right one, there’s no point in checking the other 997 pages, right? people often overlook this. inside a loop, programming languages have a command called “break” or “continue”, and you can use those to tell the program hey, I found what I need, move on to the next thing

3rd optimization:

multi-threading. you get a friend to help you. they grab a laptop, and power it on. your job is to find the paper with the matching serial number. it will definitely speed the process up, but you’re still limited by how fast you can turn the laptops on, or by how fast your friend can find the matching serial number. even if one person got the laptop, another opened it, another powered it on, another person read off the serial number from the screen, and another searched for the matching paper, and another person put the completed laptop in the completed pile, you still won’t be any faster than the slowest person. in this case, the person checking the warranty papers will probably be the slowest part. or maybe the person powering the laptop on, if the laptop takes a long time to boot up

4th optimization:

multi-processing. the above process is serial. like an assembly line. you can only go as fast as the slowest step in this assembly line. with multi-processing, however, you have parallelism. meaning you can have more than one of those lines. let’s say we have 8 people total now. 4 grabbing laptops,, turning them on, and reading the serial number to you like earlier. another 4 are checking for the matching serial number/warranty paper. even if the serial number part is the slowest, you now have 4 lines of work, so 4 people are checking at the same time. you’ll get 4x the speed in most cases by using multi-processing. when you hear about computers having “cores”, each core is like one of these 4 lines we have in this example.

that’s just the tip of the iceberg. there are tons of places to find optimizations in code, but that’s a simplified one that I think might make sense. holler if you have questions

Anonymous 0 Comments

Okay so optimization is all about making things run faster with less resources. And so the way it’s done in practice usually follows some steps

1. Run the code
2. While the code is running, a different program [called a profiler] measures things and keeps track of stuff (like how much CPU is being used, by this line of code or how much memory does this map need to be loaded).
3. After the code is finished running, all of those measures are combined into basically a list sorted by how intensive something is
4. Then as a programmer you look at that list, and you look at the things that are intensive and then you go into your bag of tricks to try and make it faster

Anonymous 0 Comments

Okay so optimization is all about making things run faster with less resources. And so the way it’s done in practice usually follows some steps

1. Run the code
2. While the code is running, a different program [called a profiler] measures things and keeps track of stuff (like how much CPU is being used, by this line of code or how much memory does this map need to be loaded).
3. After the code is finished running, all of those measures are combined into basically a list sorted by how intensive something is
4. Then as a programmer you look at that list, and you look at the things that are intensive and then you go into your bag of tricks to try and make it faster

Anonymous 0 Comments

Okay so optimization is all about making things run faster with less resources. And so the way it’s done in practice usually follows some steps

1. Run the code
2. While the code is running, a different program [called a profiler] measures things and keeps track of stuff (like how much CPU is being used, by this line of code or how much memory does this map need to be loaded).
3. After the code is finished running, all of those measures are combined into basically a list sorted by how intensive something is
4. Then as a programmer you look at that list, and you look at the things that are intensive and then you go into your bag of tricks to try and make it faster

Anonymous 0 Comments

Optimization is multi-faceted and covers a wide range of things.

Typically, when one ‘optimizes’ a game, one is trying to find the biggest overall ‘bang’ for the least possible cost — because it’s almost always a tradeoff, in time, money or resources.

The biggest optimization is how a piece of software uses memory. You can’t just shove everything into RAM and hope that it all works; there’s an efficiency bottleneck for swapping things in and out of RAM.

To optimize RAM usage, a programmer will carefully measure the size of what’s going into the RAM at any given moment. Textures are among the largest memory hogs, so RAM consumption can be lowered by using lower-resolution textures (or fewer overall) whenever possible.

The original Mario Brothers did this *wonderfully –* look at the clouds and the bushes, and you’ll see that they’re exactly the same object, with different colors. That’s a cost savings right there, because only one object needs to be loaded into RAM to display two different things.

The other way to optimize a piece of software is to figure out the most efficient way to use the CPU. Multi-threading allows a programmer to move or divide processor-intensive tasks off of the ‘main thread’ (that is, where the core of the software is expected to run) so that everything has its own space.

Think of this like a toll-booth operator moving garbage trucks and busses (which have to stop frequently) off of the main highway onto a dedicated side-road. Cars no longer get backed up behind busses and garbage trucks, so everything moves much more smoothly.

The third way to optimize a piece of software is often the easiest: simply design the software with memory and processor use in mind from the start.

Case in point: Al Lowe, the creator of *Leisure Suit Larry*, created an entire *maze* in LSL 3 by taking one single four-way ‘pathway’ scene, and using a single image of a bamboo thicket to block the exits he didn’t want the player to take. The entire thing only had to be loaded into memory once, and then it could be almost infinitely reused, for a fraction of the memory that would be required for a more elaborate maze with individual scenes.

Anonymous 0 Comments

Optimization is multi-faceted and covers a wide range of things.

Typically, when one ‘optimizes’ a game, one is trying to find the biggest overall ‘bang’ for the least possible cost — because it’s almost always a tradeoff, in time, money or resources.

The biggest optimization is how a piece of software uses memory. You can’t just shove everything into RAM and hope that it all works; there’s an efficiency bottleneck for swapping things in and out of RAM.

To optimize RAM usage, a programmer will carefully measure the size of what’s going into the RAM at any given moment. Textures are among the largest memory hogs, so RAM consumption can be lowered by using lower-resolution textures (or fewer overall) whenever possible.

The original Mario Brothers did this *wonderfully –* look at the clouds and the bushes, and you’ll see that they’re exactly the same object, with different colors. That’s a cost savings right there, because only one object needs to be loaded into RAM to display two different things.

The other way to optimize a piece of software is to figure out the most efficient way to use the CPU. Multi-threading allows a programmer to move or divide processor-intensive tasks off of the ‘main thread’ (that is, where the core of the software is expected to run) so that everything has its own space.

Think of this like a toll-booth operator moving garbage trucks and busses (which have to stop frequently) off of the main highway onto a dedicated side-road. Cars no longer get backed up behind busses and garbage trucks, so everything moves much more smoothly.

The third way to optimize a piece of software is often the easiest: simply design the software with memory and processor use in mind from the start.

Case in point: Al Lowe, the creator of *Leisure Suit Larry*, created an entire *maze* in LSL 3 by taking one single four-way ‘pathway’ scene, and using a single image of a bamboo thicket to block the exits he didn’t want the player to take. The entire thing only had to be loaded into memory once, and then it could be almost infinitely reused, for a fraction of the memory that would be required for a more elaborate maze with individual scenes.

Anonymous 0 Comments

Optimization is multi-faceted and covers a wide range of things.

Typically, when one ‘optimizes’ a game, one is trying to find the biggest overall ‘bang’ for the least possible cost — because it’s almost always a tradeoff, in time, money or resources.

The biggest optimization is how a piece of software uses memory. You can’t just shove everything into RAM and hope that it all works; there’s an efficiency bottleneck for swapping things in and out of RAM.

To optimize RAM usage, a programmer will carefully measure the size of what’s going into the RAM at any given moment. Textures are among the largest memory hogs, so RAM consumption can be lowered by using lower-resolution textures (or fewer overall) whenever possible.

The original Mario Brothers did this *wonderfully –* look at the clouds and the bushes, and you’ll see that they’re exactly the same object, with different colors. That’s a cost savings right there, because only one object needs to be loaded into RAM to display two different things.

The other way to optimize a piece of software is to figure out the most efficient way to use the CPU. Multi-threading allows a programmer to move or divide processor-intensive tasks off of the ‘main thread’ (that is, where the core of the software is expected to run) so that everything has its own space.

Think of this like a toll-booth operator moving garbage trucks and busses (which have to stop frequently) off of the main highway onto a dedicated side-road. Cars no longer get backed up behind busses and garbage trucks, so everything moves much more smoothly.

The third way to optimize a piece of software is often the easiest: simply design the software with memory and processor use in mind from the start.

Case in point: Al Lowe, the creator of *Leisure Suit Larry*, created an entire *maze* in LSL 3 by taking one single four-way ‘pathway’ scene, and using a single image of a bamboo thicket to block the exits he didn’t want the player to take. The entire thing only had to be loaded into memory once, and then it could be almost infinitely reused, for a fraction of the memory that would be required for a more elaborate maze with individual scenes.

Anonymous 0 Comments

All of these explanations have been very helpful for a tech enthusiast like me who hasn’t worked in IT in over 15 years and needs some refreshers. Thanks for the question, OP. Thanks for the responses, everyone else.

Also, if you guys would rather understand the *REAL TRUTH* about game optimization and how it’s all a big conspiracy perpetrated by Infinity Ward, the developers of Modern Warfare II, then head over to the MWII subreddit where none of these reasonable comments will go over very well.

Anonymous 0 Comments

All of these explanations have been very helpful for a tech enthusiast like me who hasn’t worked in IT in over 15 years and needs some refreshers. Thanks for the question, OP. Thanks for the responses, everyone else.

Also, if you guys would rather understand the *REAL TRUTH* about game optimization and how it’s all a big conspiracy perpetrated by Infinity Ward, the developers of Modern Warfare II, then head over to the MWII subreddit where none of these reasonable comments will go over very well.

Anonymous 0 Comments

All of these explanations have been very helpful for a tech enthusiast like me who hasn’t worked in IT in over 15 years and needs some refreshers. Thanks for the question, OP. Thanks for the responses, everyone else.

Also, if you guys would rather understand the *REAL TRUTH* about game optimization and how it’s all a big conspiracy perpetrated by Infinity Ward, the developers of Modern Warfare II, then head over to the MWII subreddit where none of these reasonable comments will go over very well.