New Python User Question about Python.

Chris Barker chrishbarker at home.net
Thu Aug 23 18:54:12 EDT 2001


Skip Montanaro wrote:
> Even though it's easier for a more experienced Python/C programmer to write
> an extension, they are still not nearly as trivial to write as the
> equivalent Python code, so there is still a subtantial barrier to clear.

Exactly. no one says the Python developers have no interest in speed,
jsut that it has not been seen as worth the very substantial effort.
Some things have been optimized, of course.
 
>     Chris> A user like myself who is a C novice, needs to put a whole lot of
>     Chris> time into that same C extension. If I could compile some Python
>     Chris> (perhaps with a few static type declarations or something) I'd be
>     Chris> a whole lot more productive!!
> 
> One thing that everyone needs to remember is that optimizing any language is
> extremely hard.  Sprinkling a few static type declarations into your Python
> code isn't going to help much either.

Given Python's dynamic nature, I imagine it would extremely difficult to
optimize. But I do think that "Sprinkling a few static type declarations
into your Python code" could help a lot given the following:

- The code can be Py2C's or straignt compiled into native code.
- You are only expecting this to work for small portions of your code
that are not very dynamic: much the same chiunks of code that can now
fairly easily be converted to C.

> it's hard, and it's time-consuming.  Perhaps if we
> all scraped together our nickels and dimes and sent them to PythonLabs
> they'd be able to hire another person to do Tim's current job so he could
> spend the next year on such a project.

As impressed as I am by Tim Peters, I imagine it would be more than a
single Tim-year to get the job done!

>     Chris> I had high hopes for the Py2C project, it seems like it had a LOT
>     Chris> of potential for allowing this, but it seems to be stalled out
> 
> There is a fundamental problem with Py2C: In many cases it gets you about a
> 2X speedup but generates huge object files.  It more-or-less unrolls the
> interpreter's main loop.  Also, since it operates at compile-time it can't
> tell what functions should be converted to C and what ones aren't worth the
> effort.  A runtime-based system could observe what functions are consuming
> the bulk of the time and just translate them.

Yes, that would be great, but it would require the above mentioned lot
of work. What I saw in Py2C was a way to build compiled modules for
those pieces of code that could benifit. Again, have it write the C for
me, where I now have to do it myself. I probably have a pretty narrow
view, but most of the stuff I end up needing to optimize are fairly
simple numeric routines. I use NumPy a lot, to I might have a function
that takes a couple of NX2 arrays of Floats, and loops through them a
few times doing something with them. If Py2C knew that they were
supposed to be NumPy arrays of floats (or lists of all Floats), it could
write the type checking code, and then those loops in straight C, just
like I end up doing by hand, but I wouldn't have to do it.

>     Chris> In short: yes, speed matters, and Python could be a far more
>     Chris> general purpose language than it is if the speed issue were
>     Chris> addressed as succesfully as it has been for LISP.
> 
> Lisp had a 30-35 year head start on Python and even today probably has a
> developer pool that is much larger than Python's.  Also, it's a bit unfair
> to compare Python's performance with commercial offerings.  Again, there are
> only so many people around who do this stuff, they only have so much time,
> and they get paid well to do what they do.

Fairness has nothing to do with it. The folks that brought us and are
continuing to bring us Python have provided a wonderful language. We're
all just jabbering on here about what it could be, not blaming anyone
for it not being that (at least I'm not). 

-Chris


-- 
Christopher Barker,
Ph.D.                                                           
ChrisHBarker at home.net                 ---           ---           ---
http://members.home.net/barkerlohmann ---@@       -----@@       -----@@
                                   ------@@@     ------@@@     ------@@@
Oil Spill Modeling                ------   @    ------   @   ------   @
Water Resources Engineering       -------      ---------     --------    
Coastal and Fluvial Hydrodynamics --------------------------------------
------------------------------------------------------------------------




More information about the Python-list mailing list