[pypy-dev] cpyext performance

Stefan Behnel stefan_ml at behnel.de
Tue Jul 10 21:19:50 CEST 2012

wlavrijsen at lbl.gov, 10.07.2012 21:02:
>> Ok, then in the case of a callback, the runtime could simply start with
>> totally stupid code that packs the low-level arguments into Python
>> arguments, attaches the low-level type information to them and then passes
>> them into the function. The JIT should then see in its trace what types
>> originally came in and optimise the argument packing away, shouldn't it?
> no, don't think so: the JIT works by seeing code execute (the "tracing" part
> of it), so with the above recipe, there's still a chicken-and-egg problem.
> That is, in order to JIT, the code in the callback needs to be executed, but
> to execute, the trace entry point is needed, but for that, the JIT needs to
> run ... circle. :/

Depends. The initial (stupid) entry point would be generated in the moment
where you assign a Python function to a C function pointer. You'd basically
pass a pointer to a wrapper function that calls your Python function.

The question is if a conversion from low-level types to Python types can be
seen and handled by the JIT, but I'd be surprised if it couldn't, since it
generates this kind of code itself anyway. It's the same as calling a
previously unoptimised (Python) branch from an optimised (low-level) one.


More information about the pypy-dev mailing list