python improvements (Was: Re: New Language)

Moshe Zadka moshez at math.huji.ac.il
Sat May 13 10:52:53 EDT 2000


On 13 May 2000, Neel Krishnaswami wrote:

> > What about array-based member lookup, vs. dict-based? I.e., if we can
> > optimize foo.bar to be either a 1) compile-time error or 2) an index to
> > the member array, it will speed up quite a lot of code.
> 
> I bet this one is really hard, because __init__ methods can contain
> arbitrary code; in legal Python code different instances of the same
> class can contain different slots. (I've seen this used extensively in
> real code, too -- people often write methods that add slots.)

But it wouldn't be legal in type-checked code. That's why the type
checking is optional: so you'll use it only where you don't need Python's
extreme dynamicity

> Most are pretty straightforward -- the things you think of first when
> you think "How can I speed up Python?" For example, Squeak stores
> caches method lookups so that it doesn't have to do nested dictionary
> lookups to find a method on each call.

You can probably implement it cyclessly if the cache doesn't increase the
instance's refcount, and you take care when deleting instances to purge
the cache first.

> I think the reason it hasn't
> been done in Python yet is because it needs cycles -- a class needs to
> know about its subclasses to tell them when the cache becomes invalid.

The trick could be that the subclasses in a class would delete
themselves from the baseclass when they destruct, no?
But I'm not sure how much this would buy -- deep hierarchies aren't
that common. However, not constructing a method object on every method
call (and later destroying it) could probably buy some optimization.

> You should *definitely* look at Squeak, then. They have defined a
> subset of Smalltalk that the image can recognize as translatable into
> C, and can optimize the hell out of.

Hmmmm...how hard do you think it would be to compile Python into
Smalltalk? STPython? (I'm reserving SPython for compiling Python into
Scheme) 

i-should-have-a-look-at-JPython-to-see-how-they-solved-multiple-inheritance-ly
y'rs, Z.
--
Moshe Zadka <moshez at math.huji.ac.il>
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com





More information about the Python-list mailing list