Your CPU is a gambler, and your if-else chains are making it lose every bet!
By Fuat Can Köseoğlu,
10 ability checks. Switch: 2ms. If-else chain: 11ms. Here's why: • Modern CPUs guess which branch you'll take before checking the condition. Wrong guess = throw away 20+ instructions, start over. Why switch statements win (see image): • If-else chains force the CPU to guess each branch. Wrong guess = pipeline flush. • Switch statements create jump tables. No guessing. Direct dispatch. The shocking truth: • Random if-else patterns = 50% misprediction rate Each misprediction = ~20 cycle penalty 10 abilities checked per frame = massive stutters. Real Unity scenarios killing your FPS: • Input handling with many keys • Ability systems with multiple skills • State machines with 10+ states • Damage type calculations Three fixes that work: • Use switch for 5+ cases • Order if-else by frequency (common cases first) • Use Dictionary for dynamic dispatch Your "readable" if-else chain might be your CPU's worst nightmare.