Are Jump Tables Always Fastest?
> Threaded code should have better branch prediction behavior than a jump table with a single dispatch point<p>This is not the case anymore, at least for modern Intel processors. Starting with the Haswell micro-architecture, the indirect branch predictor got much better and a plain switch statement is just as fast as the "computed goto" equivalent. Be wary of any references about this that are from before 2013.<p>For more info, I would recommend "Branch Prediction and the Performance of Interpreters - Don’t Trust Folklore", by Rouhou, Swamy and Seznec. Pdf link: <a href="https://hal.inria.fr/hal-01100647/document" rel="nofollow">https://hal.inria.fr/hal-01100647/document</a><p>> although indirect branch prediction should help even the field.<p>Indeed :)<p>-----<p>Fun story: I experimented with adding indirect threading to the Lua interpreter and was excited to find an improvement of up to 30% on some selected microbenchmarks (running on my IvyBridge workstation). But the improvement dropped to 0% when I tested it on a machine with a Haswell processor. Measuring with perf indicated that the improved branch predictor was indeed responsible for this.