Hacker News new | ask | show | jobs
by ramchip 1618 days ago
CPython compiles Python source code to bytecode, but it never compiles the bytecode to machine code. Instead it interprets the bytecode, reading one instruction at a time, and basically calling a giant switch statement that handles every possible opcode.

A JIT would compile the bytecode to machine code then run it directly (at least for frequently executed code paths). There is no "switch" anymore. Each bytecode instruction has already been replaced by the corresponding machine code.

1 comments

So PyPy has JIT, but not CPython, that's weird.

Is there any reason why official python doesn't have any JIT option? Would that be too fastidious to develop?

> Is there any reason why official python doesn't have any JIT option?

Desires to keep the implementation simple and approachable (relatively), as well as avoid issues of performance cliffs and such.

Also the C API has historically been extremely broad and provided large access to what amount to implementation details, making this keep working properly with a jit is difficult (at least for anything but a simplistic macro-ish JIT).

PyPy is not fully compatible with CPython. You won't have the same behaviour and CPython C API is not guaranteed to be fully compatible. So, I'm not sure that having a JIT that is fully compatible is easy.
pypy was started as an effort to make a JIT for python...when viewed in that light, it's not a weird situation at all.

as for why cpython doesn't use a jit? most likely to prevent any breakage with c modules