[Cython] Acquisition counted cdef classes

Greg Ewing greg.ewing at canterbury.ac.nz
Wed Oct 26 00:27:19 CEST 2011

Dag Sverre Seljebotn wrote:

> I'd gladly take a factor two (or even four) slowdown of CPython code any 
> day to get rid of the GIL :-). The thing is, sometimes one has 48 cores 
> and consider a 10x speedup better than nothing...

Another thing to consider is that locking around refcount
changes may not be as expensive in typical Cython code as
it is in Python.

The trouble with Python is that you can't so much as scratch
your nose without touching a big pile of ref counts. But
if the Cython code is only dealing with a few Python objects
and doing most of its work at the C level, the relative
overhead of locking around refcount changes may not be

So it may be worth trying the strategy of just acquiring
the GIL whenever a refcount needs to be changed in a nogil
section, and damn the consequences.


More information about the cython-devel mailing list