[pypy-dev] Cython-CEP: Native dispatch through Python callables

wlavrijsen at lbl.gov wlavrijsen at lbl.gov
Fri Apr 13 22:19:14 CEST 2012


Hi Stefan,

> It's not necessarily slow because a) the intermediate function can do more
> than just passing through data (especially in the case of Cython or Numba)
> and b) the exception case is usually just that, an exceptional case.

interesting: under a), what other useful work can be done by the intermediate
function?

(Yes for b), but the slowness is in having an extra layered C++ call in
between, the one that contains the try/catch. That's at least an extra 25%
overhead over the naked function pointer at current levels. Of course, only
in a micro benchmark. In real life, it's irrelevant.)

> Ok, I just took a look at it and it seems like the right thing to use for
> this. Then all that's left is an efficient runtime mapping from the
> exported signature to a libffi call specification.

It need not even be an efficient mapping: since the mapping is static for
each function pointer, the JIT takes care of removing it (that is, it puts
the results of the mapping inline, so the lookup code itself disappears).

Same goes for C++ overloads (with a little care): each overload that fails
should result in a (python) exception during mapping of the arguments. The
JIT then removes those branches from the trace, leaving only the call that
succeeded in the optimized trace. Thus, any time spent making the selection
of the overload efficient is mostly wasted, as that code gets completely
removed.

Best regards,
            Wim
-- 
WLavrijsen at lbl.gov    --    +1 (510) 486 6411    --    www.lavrijsen.net


More information about the pypy-dev mailing list