Hacker News new | ask | show | jobs
by AlexSW 459 days ago
I'm struggling to confirm that my intuition of why the compiler optimisation is faster than the naive switch expansion.

Is it about the layout of where the assembly instructions end up, and spacing around them? Or the CPU pipelining working better? Or...?

1 comments

distributing the dispatch instructions lets the predictor pick up on specific patterns within the bytecode - for example, comparison instructions are probably followed by a conditional branch instruction
Ah of course! It's improving the branch target predictor. Makes sense, thanks!