Open skirpichev opened 1 month ago
I agree with supporting PyPy. I also agree with their analysis of gmpy2_cache.c. The fix looks fine.
On Tue, Oct 15, 2024 at 11:07:49PM -0700, casevh wrote:
The fix looks fine.
Cerntaily no. I think this kill mpz caching.
Maybe I shouldn't review code when I'm exhausted. 😩
On Tue, Oct 15, 2024 at 11:19 PM Sergey B Kirpichev < @.***> wrote:
On Tue, Oct 15, 2024 at 11:07:49PM -0700, casevh wrote:
The fix looks fine.
Cerntaily no. I think this kill mpz caching.
— Reply to this email directly, view it on GitHub https://github.com/aleaxit/gmpy/issues/523#issuecomment-2415827653, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAMR23ZDRRMMZZ4E4IUGMODZ3YANJAVCNFSM6AAAAABQASNIROVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMJVHAZDONRVGM . You are receiving this because you commented.Message ID: @.***>
Performance of the CPyExt going better. Maybe we should add support for PyPy and run basic tests on CI to be sure it's working?
python -m pyperf timeit -s 'from gmpy2 import fac,mpz;a=fac(mpz(100))' 'a*a'
):On CPython - gmpy2 looks 3.8x faster. It seems using C-API is still slower than CFFI, but not too much.
I think we can do this without too much special cases (see a draft patch below):
On a pros, PyPy people are working hard to make it's support for C-API "correct first". Maybe it helps us catch some bugs. E.g. now without patching the
gmpy2_cache.c
I got for above benchmark:Is this ok to manage cache in the
tp_dealloc
as we do?simple diff to compile and get some things working:
```diff diff --git a/src/gmpy2.h b/src/gmpy2.h index 9195eeb5..4f862e20 100644 --- a/src/gmpy2.h +++ b/src/gmpy2.h @@ -71,6 +71,18 @@ extern "C" { # error "GMPY2 requires Python 3.8 or later." #endif +#ifdef PYPY_VERSION +# if SIZEOF_VOID_P >= 8 +# define PyHASH_BITS 61 +# else +# define PyHASH_BITS 31 +# endif +# define PyHASH_MULTIPLIER 1000003UL /* 0xf4243 */ +# define PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) +# define PyHASH_INF 314159 +# define PyHASH_IMAG PyHASH_MULTIPLIER +#endif + /* Include headers for GMP, MPFR, and MPC. */ #includePS: ctypes/cffi toy implementations