When you run a Python script or a Java program, the machine never directly executes your source code. Instead, the language runtime compiles it to bytecode — a sequence of compact numeric opcodes — and then a loop called an interpreter steps through those opcodes one by one, executing each.
That loop sounds trivial. But it fires billions of times per second. Every dispatch — the act of reading an opcode and jumping to the right handler — is overhead the program cannot escape. Even a single extra branch-prediction miss per opcode can cut throughput in half.
The two classic strategies, switch dispatch and threaded dispatch, make very different promises to the CPU. Understanding why one is faster reveals something surprising: the bottleneck of an interpreter is not the work it does, but the overhead of deciding what to do next. That is a lesson that echoes all the way up to JIT compilers.
Comments
Loading comments...