Python and Boehm-Demers GC, I have code.

Tim Peters tim_one at email.msn.com
Wed Jul 21 00:57:30 EDT 1999


[Tim]
>     for i in xrange(10000000):
>         pass
> [and RC vs GC implications]

[Markus Kohler]
> True.
> IMHO this is one of Pythons major design flaws.

What, specifically?

> There is no need to create a new object for each step of the loop.
> Smalltalk has loops at least as flexible as Python and it doesn't
> have this problem.

Sorry, I've missed what "the problem" is thought to be here.  Loop overhead
is typically lareger in Python programs than in other languages, but is also
typically trivial all the same.

> Loops in squeak (www.squeak.org) are already 2 to 3 times faster
> than in Python.

All possible loops?  All loops you've personally timed?  One loop you timed
in a moment of boredom <wink>?  An empty loop that counts to 10000000?  I
don't doubt that Squeak is faster in many areas and for many reasons, but
I've been running Python for most of the decade and reducing loop overhead
is about the last thing I'd bother to aim at.

> ...
> Is there anything that would prevent someone to reimplement loops
> such that only one variable is allocated ?

In the loop above, there are actually two int objects created per iteration:
the one explicitly created by xrange and bound to "i", and a hidden "loop
counter" int object used to drive the for/__getitem__ protocol.  The latter
can be (& has been, experimentally) reimplemented via an internal "mutable
int" type created for that purpose, but it didn't buy enough to be worth
adopting.  Most loop bodies contain more than "pass" <wink>, and the more
work they do the less the fixed overhead matters.

unboxing-*all*-ints-now-that-would-buy-something-ly y'rs  - tim






More information about the Python-list mailing list