python speed

Paul Boddie paul at boddie.org.uk
Wed Nov 30 14:53:41 EST 2005


Peter Hansen wrote:
> True, but so what?  Why did you suddenly change the discussion to
> require "pure" Python?

Well, comments about Python's speed usually come in the following two
forms: some Python-based solution isn't fast enough; programs written
in Python aren't fast enough. In other words, they arise either from
specific situations or from general observations gained from running
programs written only in Python (from the author's perspective, without
having written C/Pyrex/Boost extensions).

> And please define "pure" Python, given that the interpreter and many builtins, not
> to mention many widely used extension modules, are coded in C?

>From the point of view of an application developer, a "pure" Python
solution could be one where they only wrote Python code. Of course, I
can claim to deliver various solutions in "pure" Python, knowing that
some extension module that I didn't write will be doing all the hard
work, but it's useful to think of deployment complications: how easy
would it be for me to deploy my application on some obscure platform
that Python runs on? A "pure" Python solution would have limited
extension module dependencies and thus be relatively easy to deploy,
whereas a reliance on a module that hasn't been ported to RISC OS, for
example, would severely impair portability.

> And are you not allowed to use any of the performance-boosting techniques
> available for Python, like Pyrex or Psyco?

Well, from the point of view of an application developer, writing Pyrex
isn't quite the same as writing Python. There are variants of Java that
change the semantics of the language in order to achieve better
performance or certain run-time guarantees, but no-one would honestly
claim that they would be writing "pure" Java if they were really coding
for those variants.

Psyco is admittedly a tool that provides improved performance with
compatible semantics within the Python toolset. I'm not familiar with
its effect on all kinds of programs, however, but if performance was a
critical factor for a system, I wouldn't begrudge anyone from using
Psyco.

[...]

> Okay, let's compare a "pure" Python program (if you can define it in any
> meaningful, practical way) with a "pure" Java program, running on a
> non-JIT interpreter and with optimizations turned off (because, of
> course, those optimizations are umm... somehow.. not "pure"...?).

This remark is somewhat ridiculous given that the Java virtual machine
is suitably designed/specified to permit just-in-time complication.
Running Java programs on some interpreter seems like an arbitrary and
absurd exercise, especially when, by engaging in the process of writing
Java, one has already abandoned some high-level language semantics in
order to exploit the performance benefits of the virtual machine
architecture.

Sure, Python-oriented systems can be faster than Java-oriented systems,
or indeed many other kinds of systems, but such posturing on the notion
of "purity" would seem to suggest a denial of any need for an
investigation into the benefits of improved run-time performance for
programs written in Python - a view which contradicts the work done by
the most prominent project in this field, whilst reinforcing various
community perceptions and attitudes that unjustifiably consign
worthwhile work on this topic to the fringes.

Paul




More information about the Python-list mailing list