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

1.94K 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 uncountable ways of getting the same outcome, and some of those ways are faster than others.

Take a list of numbers, for example, which is in random order, and you want to sort it. It’s a fairly common problem, but how do you sort a list, exactly? A naive approach for making a list ordered might be just “Look at the first two elements, then swap their positions if they’re not in order, then move to the next two. Loop and repeat until you can’t make any more swaps.” For a small list, that works, and if you’re on your 80th workhour that week, that might be good enough.

However, that is also extremely inefficient since you end up making a ton of pointless comparisons, and the algorithm becomes awful with a long list. There are [tons of clever ways to sort a list](https://www.youtube.com/watch?v=kPRA0W1kECg) faster like merge sort, bubble sort, quicksort and a hundred others which do different tradeoffs. Some are fast on average, some are fast if the given set is almost ordered already, some take little memory, so on.

If you’re optimizing a game, you’re looking at situations like that where you’re using an inefficient solution, and replacing them with more performant ones. Maybe you have a huge list which takes a ton of memory to process, so you use a sorting algorithm which is “slower” but frees up more memory. Or maybe you look at it a bit harder and realize that you don’t actually need to sort the list in the first place, so you just remove the sorting part and the code runs 30% faster.

You are viewing 1 out of 105 answers, click here to view all answers.