how fast is Python code - another detail

Terry Reedy tjreedy at udel.edu
Fri Mar 5 02:43:36 CET 2004


"Gregor Lingl" <glingl at aon.at> wrote in message
news:404778E4.9090601 at aon.at...
>So my question: why does the
> Python interpreter not recognize this identity and internally
> replace the latter by the first in order to get *much*
> better performance?

The interpreter does not do optimization.  'Optimizing' complilers are
often buggy, which is to say, grossy dis-optimized -- as has been too often
discovered, from reports here and on PyDev, when compiling the interpreter
with 'optimzing' C compilers.

> - would this lead to wrong results in some cases?

Yes.  The identity is only an identity in this context and only dependibly
so even then for dict objects.  You can easily write a class with
__contains__() and keys() methods for which optimization would be wrong.

> - or would it be too difficult to implement?

Yes, writing significantly optimizing compiler than never introduces errors
more than base, straightforward compiler seems to be difficult.  There has
been energy put into improving the byte code set that Python is
(straightforwardly) translated into and also into improving the C code that
is executed for each byte code.

> - or is this considered a problem of minor importance?

Speed is secondary to correctness, appropriately defined.

Terry J. Reedy







More information about the Python-list mailing list