View Single Post
Old January 19, 2017, 20:15   #13
Derakon
Prophet
 
Derakon's Avatar
 
Join Date: Dec 2009
Posts: 8,552
Derakon is on a distinguished road
Quote:
Originally Posted by kandrc View Post
Floating point is sloooooowwwwww. 10s (or on some architectures even 100s) of cycles of latency, versus one cycle of latency for integer. Roguelikes have enough complicated stuff going on that this actually does matter. It's easy to end up with a compute-bound roguelike game simply by using floating point.
This might have been the case way back in the day when Angband was first written, but is really not the case any more. Certainly it is possible to make a slow roguelike by making unwise choices, but it's not going to be because you decided to use floating-point math instead of fixed-point, it's going to be because you decided to have hundreds of units all running A* pathfinding every turn, or because you're using software rendering to draw thousands of letters, one at a time, every time any aspect of the screen changes. Dumb algorithmic decisions are what will wreck you, not dumb formulaic decisions.

And the problem with the "just avoid floating point" mindset is that now every single computation you do, you have to worry about whether you're screwing things up. It's easy to introduce bugs like the above. If you just let yourself use floats then things get a lot simpler.

As always, obey these rules of optimizing:

* Is it slow? If not, don't optimize.
* Figure out what part is slow.
* Measure how slow it is.
* Optimize that part.
* Measure it again.

Optimizing almost always sacrifices clarity of code for efficiency of code, and it always results in more work being spent on a given piece of code that's otherwise functional. These are both substantial costs, so you should only optimize when it proves to be necessary.

That doesn't mean that you shouldn't be aware of broad-scale runtime implications, of course. Don't use bubble sort, that kind of thing. But your #1 concern for your code should always be does it do the right thing? Code that provides the wrong answer is worse than useless; code that is correct but slow is merely annoying.
Derakon is offline   Reply With Quote