Source

Branch

1/ @RussellPolo

A really long time ago, programming a simple game in basic on a 6502 based Commodore PET, I changed the logic from:

If then pos=pos-1
If then pos=pos+1
If…

To:
pos=pos+key2motion[keypress]

The result was a dramatic improvement. Sluggish character movement became smooth, quick motion. The result wasn’t as easy to understand, but the performance result more than justified the confusing code.

Ever since, I’ve always looked for ways to avoid branching logic. These are the types of optimizations you could never expect from a compiler.