[Python-Dev] FAT Python (lack of) performance

Victor Stinner victor.stinner at gmail.com
Mon Jan 25 17:46:45 EST 2016


Hi,

2016-01-25 23:28 GMT+01:00 Andrew Barnert <abarnert at yahoo.com>:
> On Jan 25, 2016, at 13:43, Victor Stinner <victor.stinner at gmail.com> wrote:
>>
>> According to microbenchmarks, the most promising optimizations are
>> functions inlining (Python function calls are slow :-/) and specialize
>> the code for the type of arguments.
>
> Can you specialize a function with a C API function, or only with bytecode? I'm not sure how much benefit you'd get out of specializing list vs. generic iterable or int vs. whatever from an AST transform, but substituting raw C code, on the other hand...

As I wrote in the first part of my email, I redesigned to API to make
it more generic. One of my change was to change
PyFunction_Specialize() to not only accept code objects, but any
callable object.

The PEP 510 even contains an example using a builtin function as the
specialized code:
https://www.python.org/dev/peps/pep-0510/#using-builtin-function

"On a microbenchmark, calling the C builtin takes 95 ns, whereas the
original bytecode takes 155 ns (+60 ns): 1.6 times as fast. Calling
directly chr(65) takes 76 ns."

You can design an AST optimizer to compile some functions to C and
then register them as specialized code at runtime. I have a side
project to use Cython and/or pythran to specialize some functions
using type annotation on parameters.

Victor


More information about the Python-Dev mailing list