[pypy-dev] Question about extension support

Yury V. Zaytsev yury at shurup.com
Wed Mar 26 09:31:26 CET 2014

On Tue, 2014-03-25 at 16:19 -0700, Kevin Modzelewski wrote:
> I'm curious, since I've heard a number of people mention that
> extension modules are the primary reason that PyPy is slower than
> cPython for their code; definitely an improvement over "PyPy doesn't
> run my code at all", but it's made me curious about whether or not /
> why it has to be that way.

In my opinion, it all depends on how do you use CPyExt and what your
extension modules are for. There are two scenarios here (or combinations
thereof) that I think cover most of the use cases:

1) You use C extensions to make it faster.
2) You use C extensions to steer external processes.

Ideally with PyPy you should be able to drop (1) altogether and write
nice Python code that JIT will be able to optimize sometimes even better
than hand-written C code, so here the answer would be "don't use

Now, if as a part of (2) you are doing some lengthy processing entirely
outside PyPy, this might still just as fast as with CPython with CPyExt,
but if the calls to your foreign functions are short and/or you are
transferring a lot of data C <-> PyPy, then there you go...

Personally, I've been using CPyExt and I'm very happy about it, because
the function calls take a long time, and whatever happens outside
doesn't have much to do with objects in PyPy land.

However, if my requirements were different, I would have rather
re-written everything using cffi, from what I understood it can deliver
comparable performance to cPython, and also it works both for PyPy and
cPython, not just PyPy...

Sincerely yours,
Yury V. Zaytsev

More information about the pypy-dev mailing list