----- Mail original -----
> De: "Stefan Krah" <sk...@bytereef.org>
> À: "numpy-discussion" <numpy-discussion@python.org>
> Envoyé: Mercredi 7 Mai 2025 13:47:19
> Objet: [Numpy-discussion] Re: Better compatibility of the Python 
> scientific/data stack with fast Python interpreters

> On Wed, Apr 30, 2025 at 02:08:36PM +0200, PIERRE AUGIER wrote:
>> It seems to me that a strategy based on HPy would give practical benefices 
>> for
>> users in a much shorter time (typically few years) than just waiting for
>> CPython C API evolution.
> 
> It would be nice to use alternative interpreters, but I still see conflicting
> messages about the performance of HPy:
> 
> https://github.com/psycopg/psycopg/issues/154
> 
> "If the goal is to run psycopg3 fast in PyPy, there are at least three paths:
> 
>    use a cffi backend: this is likely to be the fastest one
>    (in case psycopg uses Cython and doesn't call directly any CPython C API): 
> use
>    the Cython HPy backend, once it's ready
>    (in case psycopg uses the CPython C API directly): rewrite it to use HPy
>    instead."

One can create from a C file using the HPy API a standard Python extension 
using in the background the CPython C API. So for CPython, there should be no 
performance penalty. Numpy-HPy should be on CPython as fast as current Numpy.

From the same file, one can also create a universal extension that can be used 
on different Python implementations (and for different Python versions). On 
CPython, there is a relatively small performance penalty (few percents). On 
PyPy and GraalPy, the calls are basically as fast as on CPython with the 
standard Python extension.

Then, there can be other performance improvements with other methods, some 
already possible (in particular on GraalPy) and some that would need further 
HPy developments (avoiding boxing/unboxing).

> CFFI however is slower, e.g. for _decimal, than the native CPython C-API.
> (At least it was in version 3.9, _decimal has been slowed down significantly
> since I left.)

Could you explain a bit more? Or provide a link? CFFI with PyPy? or CFFI with 
CPython? Is there a proper reproducible benchmark?

> _decimal of course operates on scalars and has many API calls, so maybe
> for NumPy this is not relevant except for small arrays.

Yes, for most real world code using Numpy, the performance of the interface is 
not crucial for the overall program performance. It is just important to avoid 
very inefficient things, like the emulation layers needed with the CPython C 
API (like PyPy cpyext).

> Or perhaps HPy has evolved in the meantime (the above GitHub thread is from
> 2022).
> 
> 
> Stefan Krah
> 
> _______________________________________________
> NumPy-Discussion mailing list -- numpy-discussion@python.org
> To unsubscribe send an email to numpy-discussion-le...@python.org
> https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
> Member address: pierre.aug...@univ-grenoble-alpes.fr
_______________________________________________
NumPy-Discussion mailing list -- numpy-discussion@python.org
To unsubscribe send an email to numpy-discussion-le...@python.org
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: arch...@mail-archive.com

Reply via email to