[ann] Minimal Python project

Andrew McGregor andrew at indranet.co.nz
Sat Jan 11 04:51:38 CET 2003

--On Friday, January 10, 2003 23:37:09 +0000 "Edward K. Ream" 
<edream at tds.net> wrote:

>> As Armin Rigo of PSYCO fame takes part in the effort,
> we are confident that MinimalPython will eventually
> run faster than today's CPython.
> This announcement seems to be making a truly remarkable claim, namely that
> one could increase the speed of  C code by recoding it in Python and then
> applying Psycho to it.

Yep, you can!  It takes a pretty strange piece of code, but it does happen. 
For instance, I've written a key-management protocol in Python, and it 
really is faster than the C implementations of the same thing when certain 
key functions are fed to psyco.  (of course, this may just say that I have 
a better feel for algorithm design)

> I am inclined to disbelieve this claim.  Why should Psycho be able to do
> better than an optimizing C compiler applied to hand-written interpreter
> code and/or library code?  The only possibilities I can think of:
> 1. The GIT somehow has access to enough run-time information to perform
> some truly excellent optimizations.

This one :-)  For instance, in a dynamic language, you can't know until 
runtime if some argument to a method has constant type or (better) constant 
value, but a JIT can discover and use this.  If it does not, and someone 
passes it a different type or value, the JIT can then discover this and 
compile a new version that handles that type, optimised.  Note that the 
constant value case can't be optimised by a C compiler, unless the function 
is inlined, which doesn't happen in big programs very much because the 
function will often be in another module.

It is also possible to inline method calls, merge methods if they are often 
called in a particular sequence, and then optimise over the results.  C 
compilers, because of modular compilation again, often can't do this either 
(although a particularly fancy compiler might; it needs an integrated build 
system to make this possible).

> 2. The granularity of the data processed by the GIT somehow is big enough
> to again affect some excellent optimizations.

Maybe so, I'm not sure.

> 3. There are other marvelous optimizations, unknown to me and available
> neither to Guido nor to an optimizing compiler that can be applied.
> My guess is that none of these are true.  Furthermore, I suspect that if
> such optimizations are available to the GIT the optimizations could also
> be made available either to Guido or to optimizing C compilers.  Note
> that the fact that Psycho can improve Python code is not, by itself, an
> indication that it could improve the corresponding C code!
> Would anyone care to enlighten me how MinimalPython will achieve its
> stated goals?
> Edward
> --------------------------------------------------------------------
> Edward K. Ream   email:  edream at tds.net
> Leo: Literate Editor with Outlines
> Leo: http://personalpages.tds.net/~edream/front.html
> --------------------------------------------------------------------
> --
> http://mail.python.org/mailman/listinfo/python-list

More information about the Python-list mailing list