[pypy-dev] CFFI: better performance when calling a function from address

Armin Rigo armin.rigo at gmail.com
Wed Sep 26 17:05:05 EDT 2018


Hi Carl Friedrich,

On Wed, 26 Sep 2018 at 22:28, Carl Friedrich Bolz-Tereick <cfbolz at gmx.de> wrote:
> Couldn't that slowness of getattr be fixed by making the lib objects eg use module dicts or something?

If we use the out-of-line API mode then ``lib`` is an RPython object,
but if we use the in-line ABI mode then it's a pure Python object.
More precisely it's a singleton instance of a newly created Python
class, and the two extra instructions are reading and guard_value'ing
the map.

It might be possible to rewrite the whole section of pure-Python code
making the ``lib`` for the in-line ABI mode, but that looks like it
would be even slower on CPython.  And I don't like the idea of
duplicating---or even making any non-necessary changes to---this
slightly-fragile-looking logic...

Anyway, I'm not sure to understand how just a guard_value on the map
of an object can cause a 250 ns slow-down.  I'd rather have thought it
would cause no measurable difference.  Maybe I missed another
difference.  Maybe the effect is limited to microbenchmarks.  Likely
another mystery of modern CPUs.


A bientôt,

Armin.


More information about the pypy-dev mailing list