Search code examples
pythoncythonpypy

Using Cython with PyPy can speed up?


I've written a transpiler in python which works well with PyPy. Now I'm thinking to speed up more my existing code base with cython.

Will Using Cython with pypy increase or decrease the performance?

I'm using PyPy 3.9 and here's my code https://github.com/ad1b003/Ethan-A-Programming-Language


Solution

  • Cython should mostly work with PyPy.

    As with all performance questions, the key is to test it, however:

    • If you are mainly manipulating Python objects then you will probably slow PyPy down. You force it to use its cpyexp compatibility layer, which isn't hugely fast and restricts how much it can JIT compile the surrounding code.
    • If you're manipulating large arrays through "typed memoryviews" then this should work well: you have fast access to a region of memory and you're not forcing PyPy to make much use of its compatibility layer.

    A quick look at your GitHub repository suggests it's mostly the former, so I would not expect a benefit.