2.6, 3.0, and truly independent intepreters

Terry Reedy tjreedy at udel.edu
Thu Oct 30 19:39:54 CET 2008

Andy O'Meara wrote:
> On Oct 28, 6:11 pm, "Martin v. Löwis" <mar... at v.loewis.de> wrote:

>> You should really reconsider writing performance-critical code in
>> Python.
> I don't follow you there...  Performance-critical code in Python??

Martin meant what he said better later
 >> Again, if you do heavy-lifting in Python, you should consider to
 >> rewrite the performance-critical parts in C.

> I tried to list some abbreviated examples in other posts, but here's
> some elaboration:
> The common pattern here is where there's a serious mix of C and python
> code and data structures,

I get the feeling that what you are doing is more variegated that what 
most others are doing with Python.  And the reason is that what you are 
doing is apparently not possible with *stock* CPython.  Again, it is a 
chicken-and-egg type problem.

You might find this of interest from the PyDev list just hours ago.
Hi to all Python developers

For a student project in a course on virtual machines, we are
evaluating the possibility to
experiment with removing the GIL from CPython

We have read the arguments against doing this at

But we think it might be possible to do this with a different approach
than what has been tried till now.

The main reason for the necessity of the GIL is reference counting.

We believe that most of the slowdown in the free threading
implementation of Greg Stein was due to the need of atomic
refcounting, as this mail seems to confirm:

So we want to change CPython into having a "real" garbage collector -
removing all reference counting, and then the need for locks (or
atomic inc/dec ops) should be
highly alleviated.

Preferably the GC should be a high-performance one for instance a
generational one.

We believe that it can run quite a lot faster than ref-counting.

Shared datastructures would get their lock obviously.
Immutable objects (especially shared global objects, like True, False, Null)
would not.

Most of the interpreter structure would be per-thread, at that point.

We do not know how Greg Stein did his locking in the free threads
patch, but as a part of the course we learned there exists much faster
ways of locking than using OS-locks (faster for the uncontented case)
that are used in e.g. the HOT-SPOT java-compiler. This might make
"free threading" in python more attractive than some pessimists think.
In particular, we are talking about making the uncontended case go fast,
not about the independent part of stack-allocating the mutex
structure, which can only be done and is only needed in Java.

These ideas are similar to the ones used by Linux fast mutexes
(futexes), the implementation of mutexes in NPTL.

We have read this mail thread - so it seems that our idea surfaced,
but Greg didn't completely love it (he wanted to optimize refcounting

He was not totally negative however. His main objections are about:
- cache locality (He is in our opinion partially right, as seen in some
other paper time ago - any GC, copying GC in particular, doubles the
amount of used memory, so it's less cache-friendly). But still GCs are
overall competitive or faster than explicit management, and surely
much faster of refcounting.

We know it is the plan for PyPy to work in this way, and also that
Jython and Ironpython works like that (using the host vm's GC), so it
seems to be somehow agreeable with the python semantics (perhaps not
really with __del__ but they are not really nice anyway).

Was this ever tried for CPython?

Any other comments, encouragements or warnings on the project-idea?

Best regards: Paolo, Sigurd <stm at daimi.au.dk>

Guido's response
It's not that I have any love for the GIL, it just is the best
compromise I could find. I expect that you won't be able to do better,
but I wish you luck anyway.

And a bit more explanation from Van Lindberg
Just an FYI, these two particular students already introduced themselves
on the PyPy list. Paolo is a masters student with experience in the
Linux kernel; Sigurd is a PhD candidate.

Their professor is Lars Bak, the lead architect of the Google V8
Javascript engine. They spent some time working on V8 in the last couple

I agree that you should continue the discussion.  Just let Martin ignore 
it for awhile until you need further input from him.

Terry Jan Reedy

More information about the Python-list mailing list