[math4] pure python may be a bad idea

Tomeu Vizoso tomeu at sugarlabs.org
Wed Apr 8 03:50:14 EDT 2009


On Tue, Apr 7, 2009 at 23:54, Christian Horne <blendmaster1024 at gmail.com> wrote:
> okay, I guess I am used to needing to be unusually optimized:
>
> most python i write is meant to drive 60hz video game logic, where you can't
> have any long loops because they'll slow it down a whole 30 hz.

That kind of code I certainly wouldn't write all in python.
Interpreted languages shine when being used as glue code, the basic
components being written in C/C++. If you cannot find a set of
components that do all you want, then you need to write some of them
in C yourself, and then use python to tie them all.

This makes sense only because glue code should amount for the 90% of
the code that needs to change more often, thus making the app easier
to maintain and modify, while not hurting performance too much.

Regards,

Tomeu

> On Tue, Mar 31, 2009 at 10:05 AM, Tomeu Vizoso <tomeu at sugarlabs.org> wrote:
>>
>> 2009/3/31 Wade Brainerd <wadetb at gmail.com>:
>> > On Mon, Mar 30, 2009 at 5:32 PM, Christian Horne
>> > <blendmaster1024 at gmail.com>
>> > wrote:
>> >>
>> >> ... and why?
>> >> because python is relatively slow.
>> >> i'm not saying that python in general is bad, but everything that can
>> >> be
>> >> coded as a C/C++ PYModule probably should be, as python is noticably
>> >> slower.
>> >
>> > Hey Christian,
>> >
>> > If you think about what the Python code is actually doing, this isn't
>> > really
>> > true.   We're not crunching numbers or doing heavy 3D transformation or
>> > image processing.
>> >
>> > In Sugar activities, Python code executes effectively instantly.  All
>> > the
>> > hard work happens inside Cairo, Pygame, the X driver, Numeric, etc.
>> > which
>> > are already all written in C.
>> >
>> > Take it from me, two of my Sugar activities (Colors! and Bounce) rely on
>> > C
>> > extension modules.  In both cases, I stayed in Python as long as I could
>> > before moving anything to C.  With tools like SWIG available, it's an
>> > easy
>> > transition to make if you found find you need to.
>> >
>> >> i can say this for sure, not just because of all the places you hear
>> >> that
>> >> interpreted is slower (and i'm not saying they're wrong) but because
>> >> XFCE runs at least 2x faster on my XO than sugar does.
>> >
>> > Sugar's performance has a lot more to do with what its Python code is
>> > doing
>> > than the fact that it's running Python.  Not enough attention has been
>> > paid
>> > to optimizing it.
>>
>> +1 from someone who has spent lots of time understanding the
>> performance behavior of Sugar.
>>
>> Regards,
>>
>> Tomeu
>
>


More information about the FourthGradeMath mailing list