The Cost of Dynamism (was Re: Pyhon 2.x or 3.x, which is faster?)

Marko Rauhamaa marko at pacujo.net
Thu Mar 24 10:16:39 EDT 2016


BartC <bc at freeuk.com>:

> And forgetting Python for a minute and concentrating only on its
> byte-code as a language in its own right, how would you go about the
> job of streamlining it?

CPython's bytecode is not crucial for CPython's execution speed. The
bytecode is mainly a method of improving the performance of loading
modules. IOW, it seeks to optimize parsing.

CPython's VM does not have to execute the bytecode as-is. It can further
compile and reprocess it internally to optimize speed and other
attributes.

As far as CPython is considered, a .pyc file contains precisely the same
information as the .py file. Thus, executing .pyc is no faster than
executing a .py file (ignoring the parsing overhead). The only advantage
of streamlining bytecode is to speed up load times, which is a complete
nonissue in most production environments.

Really, your optimization efforts should concentrate not on bytecode but
on runtime data structures, algorithms, heuristics, equivalence
transformations, reachability analysis, profiling and such.


Marko



More information about the Python-list mailing list