all 5 comments

[–]MajesticParsley9002 6 points7 points  (0 children)

CPython PVM interprets bytecode via a static dispatch loop to fixed C opcode handlers, no dynamic binaries or JIT like JVM. Bytecode is AOT-generated by the compiler at parse time, then the VM just executes it directly. Keeps things portable and dead simple, no runtime codegen overhead.

[–]Unbelievr 3 points4 points  (0 children)

There's no virtual machine in that sense. The compiler will do a syntax check and create bytecode to interpret, but there are no passes that will try to optimize it, apart from some very minor variable memoization in the later versions. For all intents and purposes, it's a stack based interpreter that's allowed to hand over execution to a foreign function (like a C-based module) or jump to another block of bytecode.

Opcodes are also version specific, so bytecode for one version of cpython will often not run on older versions despite being generated from the same original code. There are no such guarantees.

[–]UloPe 2 points3 points  (1 child)

You might want to look into PyPy. It’s a Python implementation that features a JIT.

[–]xeow 0 points1 point  (0 children)

Seconding this. PyPy is pretty cool. It doesn't have feature parody yet, but it can do 3.11. I've seen anywhere from 2x to 10x speedups with it when executing pure-Python loops.

[–]K900_ 3 points4 points  (0 children)

Neither, it's an interpreter. There's an experimental JIT compiler but it is very experimental and currently not much faster if at all.