Idle bytecode query on apparently unreachable returns

Raymond Hettinger python at rcn.com
Tue Oct 11 07:03:36 EDT 2005


[Tom Anderson]:
> What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't
> reachable? Does the compiler just throw in a default 'return None'
> epilogue, with routes there from every code path, even when it's not
> needed? If so, why?

Since unreachable code is never executed, there is no performance
payoff for optimizing it away.  It is not hard to write a dead-code
elimination routine, but why bother?  It would save a few bytes, slow
down compilation time, save nothing at runtime, and make the compiler
more complex/fragile.

FWIW, the peephole optimizer in Python/compile.c is mature -- the low
hanging fruit has already been harvested, leaving the field of
remaining optimizations somewhat barren.


Raymond




More information about the Python-list mailing list