Python optimization (was Python's "only one way to do it" philosophy isn't good?)

Josiah Carlson josiah.carlson at sbcglobal.net
Mon Jun 11 08:34:49 CEST 2007


John Nagle wrote:
> Josiah Carlson wrote:
[snip]
>> Constant folding happens regardless of optimization level in current 
>> Pythons.
> 
>> So really, assert and docstring removals.  Eh.
> 
>    It's hard to optimize Python code well without global analysis.
> The problem is that you have to make sure that a long list of "wierd
> things", like modifying code or variables via getattr/setattr, aren't
> happening before doing significant optimizations.  Without that,
> you're doomed to a slow implementation like CPython.
> 
>    ShedSkin, which imposes some restrictions, is on the right track here.
> The __slots__ feature is useful but doesn't go far enough.
[snip]
> Python could get much, much faster.  Right now CPython is said to be 60X 
> slower
> than C.  It should be possible to get at least an order of magnitude over
> CPython.

Don't get me wrong; I'm all for adding optimizations, I was merely 
expressing that currently, 'python -OO' doesn't really do a whole lot. 
I've a long-time user of psyco, have mucked about with 
scipy.weave.inline, and have been a heavy user of Pyrex and C.  If there 
was a method of offering some simple optimization cues to the Python 
runtime to improve its speed, I would be happy to add them when I really 
care about speed (I already do more than that when writing Pyrex).  The 
real question is whether we can get a practical implementation of these 
optimizations as easy to use as psyco.


  - Josiah



More information about the Python-list mailing list