Bytecode optimisation
Michael Vanier
mvanier at bbb.caltech.edu
Thu May 20 22:44:57 EDT 1999
graham at sloth.math.uga.edu (Graham Matthews) writes:
> Christian Tismer (tismer at appliedbiometrics.com) wrote:
> : There is just a small socket of speed penalty for using Python.
> :
> : The bad thing is that when your objects become tiny and simple,
> : the necssary operations become very small, and what remains
> : is now the small Python socket, which is tuned into a mountain
> : by that.
> :
> : Therefore, I see no need to make Python faster in all cases,
> : but just in the small simple ones, where my collegues say
> : "hey, nice done in Python, but why is it 50 times faster in C?"
> :
> : Instead, I want Python to become as dumb as C for small
> : problems, whereby keeping its wonderful flexibility for
> : the rest.
>
> My point was that I very very much doubt that you can do what you
> want, namely retain Python's flexibility AND have C like performance
> for the small things. Flexible semantics almost always imply poor
> performance. There are some exceptions to this rule, notably Self,
> but they are very rare, and tend to involve either excruiating
> design care from the start (eg. Self was really designed with the
> optimisations it does in mind), or a good deal of opportunism and
> luck. Since Python was not designed to be fast (rather it was
> designed to be flexible), you are going to have to be very very
> lucky to get your C performance.
>
> graham
Counterexample: Common Lisp, which is just as flexible as python (probably
more so), but also allows optional type declarations that can give speedups
approaching C speed in many cases. Also Dylan, although Dylan has not been
developed to nearly the same extent (and anyway, Dylan is basically infix CL).
There *is* a flexibility-versus-speed tradeoff, of course, but that doesn't
mean you can't have both in one language. I suspect most hardcore python
programmers would rather change:
def munge(a, b):
return 2 * a + 3 * (a - b)
to (pseudo-python)
def munge(a, b):
declare a, b, return: int # a, b, and return value are ints
return 2 * a + 3 * (a - b)
than recode in C all the time. This is the kind of direction I'd like to
see python 2.x take.
Mike
-------------------------------------------------------------------------
Mike Vanier mvanier at bbb.caltech.edu
Department of Computation and Neural Systems, Caltech 216-76
Will optimize nonlinear functions with complex parameter spaces for food.
More information about the Python-list
mailing list