CFFI in ABI mode vs ctypes performance with Pypy?

35 views
Skip to first unread message

AJ R

unread,
Jul 25, 2022, 11:28:34 AM7/25/22
to pytho...@googlegroups.com
Hi,

I inherited a lot of Python 2.7 code and I was tasked to port this to Python 3. I decided to use Pypy 3.8 to improve performance of this long running data linkage program.

I've started profiling the program and (not surprisingly) a record sorting step is a hotspot. The code currently uses ctypes to call C functions in a .dll. I am not sure if the source code for the .dll is still available. The sort routine uses temporary files to do its job.

Now my question is: will it be worth my time to convert the ctypes code into CFFI code (ABI mode)? Or *might* this only be faster if I use a CFFI-made .dll (API mode)? Additionally, what compiler is needed if I would be able to follow the API route (Win10/64).

Thanks in advance!

Best wishes,
Albert-Jan



Armin Rigo

unread,
Jul 26, 2022, 5:42:05 AM7/26/22
to pytho...@googlegroups.com
Hi,
Yes, using CFFI is definitely quite a lot faster than using ctypes on
PyPy. This is true for both the ABI and the API mode of CFFI. The
performance difference between the ABI and the API modes of CFFI might
or might not be relevant in your use case; I think for many cases it
doesn't make a difference. I would try first to use the ABI mode
because it's closer to ctypes and usually sufficient if you target
only a single platform with a well-defined ABI, like 64-bit Windows.


A bientôt,

Armin.

AJ R

unread,
Jul 26, 2022, 6:57:39 AM7/26/22
to python-cffi
Hi Armin,

Thanks for your prompt reply! Useful to know that ABI is still faster than ctypes.
I'll try this next week when my vacation is over.

Best wishes,
Albert-Jan

Op dinsdag 26 juli 2022 om 11:42:05 UTC+2 schreef Armin Rigo:
Reply all
Reply to author
Forward
0 new messages