bpo-43760: Check for tracing using 'bitwise or' instead of branch in dispatch. by markshannon · Pull Request #28723 · python/cpython

About 1% faster

Use bitwise or instead of additional jump to handle tracing in dispatch.

What was:

    if (use_tracing)
        goto tracing_dispatch
    goto *jump_table[opcode];

becomes:

     goto *jump_table[opcode | use_tracing];

use_tracing is now either 0 or 255

Special opcode 255 (DO_TRACING) handles tracing and then jumps to the original instruction.

The main complexity comes from needing access to the last instruction when tracing. This means that we update frame->f_lasti and next_instr at the start of the instruction, instead of at the end of the previous instruction.

https://bugs.python.org/issue43760