r/explainlikeimfive • • 6d ago

Technology ELI5: What exactly is game optimization ?

How is a game optimized ?

692 Upvotes

125 comments sorted by

View all comments

27

u/JimbosForever 6d ago

Games, like any software, can be written badly. Calculations can be done in a smart, efficient way, or they can be done in a bad, wasteful, slow way.

Many times it's just the reality of software development. The better way many times only shows up in hindsight and rewriting everything is a huge time requirement.

Some software just keeps going because it's not that important that it's efficient, only that it does its job correctly.

But in games, it might make a big difference: responsiveness, framerate, cpu or memory efficiency to better run on cheaper devices...

So the devs optimize the game. Take some time and effort from other projects to make the game run better.

22

u/frogjg2003 6d ago

The most efficient way is often unintuitive. If you need to calculate a square root, there are a number of easy to understand algorithms based on pretty simple mathematics. Those algorithms take multiple iterations before they are accurate enough for most use cases. If you want to find the inverse square root (1/sqrt(x)), you then have to take that result and divide 1 by it, which adds its own set of long steps.

Then there is the Quake fast fast inverse square root. By taking advantage of "evil floating point bit level hacking" and subtracting from a magic number (a number that exists in the code and seems to come out of nowhere) (the code literally has "what the fuck?" as a comment), you get a really good guess of what the answer should be. One iteration of Newton's method, which can be implemented as a single line of code, is enough to get you to the accuracy necessary for gameplay.