Is python not good enough?

David Cournapeau cournape at gmail.com
Sun Jan 17 04:08:17 CET 2010


On Sun, Jan 17, 2010 at 11:43 AM, John Nagle <nagle at animats.com> wrote:
> David Cournapeau wrote:
>>
>> On Sun, Jan 17, 2010 at 4:17 AM, John Nagle <nagle at animats.com> wrote:
>>>
>>> Nobody wrote:
>>>>
>>>> On Fri, 15 Jan 2010 12:34:17 -0800, John Nagle wrote:
>>>>
>>>>>   Actually, no.  It's quite possible to make a Python implementation
>>>>> that
>>>>> runs fast.  It's just that CPython, a naive interpreter, is too
>>>>> primitive
>>>>> to do it.  I was really hoping that Google would put somebody good at
>>>>> compilers in charge of Python and bring it up to production speed.
>>>>>
>>>>>   Look at Shed Skin, a hard-code compiler for Python
>>>>
>>>> A hard-code compiler for the subset of Python which can easily be
>>>> compiled.
>>>>
>>>> Shed Skin has so many restrictions that it isn't really accurate to
>>>> describe the language which it supports as "Python".
>>>>
>>>> Hardly any real-world Python code can be compiled with Shed Skin. Some
>>>> of
>>>> it could be changed without too much effort, although most of that is
>>>> the
>>>> kind of code which wouldn't look any different if it was implemented in
>>>> C++ or Java.
>>>>
>>>> The monomorphism restriction is likely to be particularly onerous: the
>>>> type of a variable must be known at compile time; instances of
>>>> subclasses
>>>> are allowed, but you can only call methods which are defined in the
>>>> compile-time class.
>>>>
>>>> If you're writing code which makes extensive use of Python's dynamicity,
>>>> making it work with Shed Skin would require as much effort as re-writing
>>>> it in e.g. Java, and would largely defeat the point of using Python in
>>>> the
>>>> first place.
>>>>
>>>> http://shedskin.googlecode.com/files/shedskin-tutorial-0.3.html
>>>>
>>>> If you want a language to have comparable performance to C++ or Java,
>>>> you
>>>> have to allow some things to be fixed at compile-time. There's a reason
>>>> why C++ and Java support both virtual and non-virtual ("final") methods.
>>>
>>>   My point is that Python is a good language held back by a bad
>>> implementation.  Python has gotten further with a declaration-free syntax
>>> than any other language.  BASIC and JavaScript started out
>>> declaration-free,
>>> and declarations had to be retrofitted.  Python has survived without
>>> them.
>>> (Yes, there are hokey extensions like Psyco declarations and
>>> "decorators",
>>> but both are marginal concepts.)
>>
>> There are efficient implementations of dynamic programming languages
>> which do not rely on declaration (if by declaration you mean typing
>> declaration), even when available:
>>
>> http://strongtalk.googlecode.com/svn/web%20site/history.html
>>
>> See also:
>>
>> http://www.avibryant.com/2008/05/those-who-misre.html
>
>   Yes, that's my point.

Compilation with global type inference may be a good way to speed up
python, but it is not the only way. Your claim about lookups does seem
to contradict how the various efficient implementations of dynamic
languages work. For example, the V8 engine deal with dynamic
attributes without static analysis:

http://code.google.com/apis/v8/design.html

So JIT may be limited, but I don't think it applies to the examples
you have given. Maybe static analysis ala stalin is needed for very
fast execution.

I don't claim any knowledge on those technologies, but my impression
is that other forces held back a fast python implementation, in
particular compatibility with C extensions. For example, I know no
fast implementation of dynamic languages which do not rely on garbage
collection: if this is indeed true, it may mean that retrofitting a gc
everywhere is needed, but doing so without breaking C extensions is
hard (if at all possible ?). And certainly, one of the big reason for
the python success is easy interface with C. Maybe interfacing with C
is the real reason for holding back python implementations ?

cheers,

David



More information about the Python-list mailing list