News for hackers. Stuff that matters.
Re:Squeezing a Little More Performance Out of Bytecode Inter... by _a_a_a_ on Monday June 19, 2023 @03:54AM (#36388444)
> So you are questioning the effect of direct threading code?

No, cos I said "the benchmarks speak for themselves". But I am trying to understand why it's better and under what circumstances.

Re:Squeezing a Little More Performance Out of Bytecode Inter... by kaba0 on Monday June 19, 2023 @05:13AM (#36388942)
I meant it in terms of whether your question is about the reordering or the direct threading vs naive switch-loop.
Re:Squeezing a Little More Performance Out of Bytecode Inter... by _a_a_a_ on Monday June 19, 2023 @05:10PM (#36396508)
The direct threading is what interests me. From a link provided above by ghusbands https://eli.thegreenplace.net/2012/07/12/computed-goto-for-e...

"...and the goto version is 25% faster than the switch version...

Comments inside the CPython implementation note that using computed goto made the Python VM 15-20% faster"

(Which isn't the 2-4x speed up that you found).

In that link they say that part of the reason is because of the bounds checking which is automatically done by the switch statement.

What I'm struggling with which is no doubt down to my lack of knowledge, is why it should be significantly faster (if you take out or disable the bounds checking added by the switch). I can see there would be some advantage in spreading out the jumps so the branch predictor could work a bit better, but I am surprised at the speed up. I guess mispredicted branches are so expensive that doing just a little bit better could account for the difference, but I am trying to understand it.