[pypy-dev] libgmp

Amaury Forgeot d'Arc amauryfa at gmail.com
Fri Feb 24 10:27:30 CET 2012


Hi Stefan,

2012/2/24 Stefan Behnel <stefan_ml at behnel.de>

> So, as a reply to the OP: seeing the current advances in getting Cython
> code to run in PyPy (interfacing at the C-API level), another option would
> be to do exactly as you would in CPython and implement the performance
> critical parts of the code that heavily rely on gmp interaction in Cython
> (to get plain C code out of it), and then import and use that from PyPy,
> but at a much higher level than with direct individual calls to the gmp
> functions. However much faster ctypes can be in PyPy than in CPython, you
> just can't beat the performance of a straight block of C code when the goal
> is to talk to C code. Cython will also allow you to run code in parallel
> with OpenMP, in case you need that.
>

Cython won't be fast with PyPy. The C code it generates is too much
specialized for CPython.
For example, I've seen huge slowdowns in the Cython program itself (while
compiling lxml, for example)
when the various Cython extension modules (Nodes.c for example) started to
compile and became
available for pypy.
I was about to write the list of operations that cpyext performs for
PyTuple_GET_ITEM,
but this macro is too large to fit in the margin :-)
And PyDict_Next is a nightmare:
https://bitbucket.org/pypy/pypy/src/9f0e8a37712b/pypy/module/cpyext/dictobject.py#cl-177

It's one thing to be able to run lxml and other Cython-based libraries with
pypy.
it's another thing to pretend that Cython is the way to write fast modules
on pypy.
You may win on the generated C code, but will loose when interfacing with
the rest
of the Python interpreter (which is also the reason why ctypes is so slow).

This said, I've added all the functions you mentioned in a previous email.
You may try your tests again with the nightly build.

-- 
Amaury Forgeot d'Arc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/pypy-dev/attachments/20120224/91555bda/attachment.html>


More information about the pypy-dev mailing list