[Python-ideas] Add specialized bytecode with guards to functions

Antoine Pitrou antoine at python.org
Wed Oct 21 23:09:07 CEST 2015


Victor Stinner <victor.stinner at ...> writes:
> 
> 2015-10-21 18:20 GMT+02:00 Guido van Rossum <guido at ...>:
> >  I haven't tried the prototype yet, but I wonder if this mightn't be a
> > useful addition to an existing optimizing Python system, e.g. PyPy or (plug
> >  Pyston?
> 
> I'm not sure that specialized functions with guards would benefit to
> JIT compilers.
> 
> A best match is with Cython, pythran and other projects generating a
> specialized version of a function (in native code), maybe releasing
> the GIL. It would be cool to be able to use a specialized version
> under some conditions. For example, if parameters are all floats, use
> the specialized version optimized by Cython, other fallback to the
> (slow) regular bytecode. The challenge is to automate everything and
> make it easy to use.
> 
> I don't know if Numba would match with this design.

Numba is primarily a JIT compiler but next release will also feature
a limited AOT compilation mode (meaning you can compile extension
modules for given explicit signatures of whatever functions you want
to compile, and don't need Numba to import or run those functions).
Documentation preview here:
http://numba.pydata.org/numba-doc/dev/user/pycc.html

As a JIT compiler, however, Numba is special as it's opt-in and doesn't
claim to support the whole range of Python semantics (far from it).
Numba takes your Python code and pretty much assumes it has the same
dynamicity as Fortran and C++ code, runs type inference and compiles
a very fast version out of it, for the CPU (by default) or for the
GPU (with a specific programming model).

Regards

Antoine.




More information about the Python-ideas mailing list