[Python-Dev] VM and Language summit info for those not at Pycon (and those that are!)

Stefan Behnel stefan_ml at behnel.de
Sun Mar 20 12:56:22 CET 2011


Jesse Noller, 20.03.2011 12:32:
> On Sun, Mar 20, 2011 at 7:19 AM, Stefan Behnel wrote:
>> It appears that there has been little mention of Cython at the summit,
>> despite of the speed of CPython being a major topic, according to the notes.
>> I can see several areas where Cython could help in speeding up core CPython,
>> one of the most obvious being compilation of standard library modules, and
>> JIT-like compilation of Python modules at import time.
>>
>> Nick mentioned that there was a discussion of making C-only modules
>> available as alternative Python implementations. I'd like to suggest the
>> opposite as well: make pure Python stdlib modules optionally compilable to
>> fast C code using Cython. The obvious advantages are a) speed and b) a
>> single code base for both Python and C modules.
>
> The reason why there was no mention is probably because no one
> intimately familiar with Cython was there, and if they were - it was
> not brought up. If Cython supports PyPy - and Jython, and IronPython,
> your proposal makes sense. The reason for "pure" python implementation
> is so that other implementations can share the exact same standard
> library we have today. I don't see adding a cython version as helping
> that.

Cython is meant to compile Python code. A "cython version" would just be a 
pure Python module, usable with all other implementations, but with type 
annotations that make it compile to more optimal C code. Type annotations 
can be provided in an external file (.pxd), using decorators and/or using 
Python 3 annotation syntax. There's also a port of Cython to IronPython 
being written. Additionally, other implementations (such as PyPy) could 
start using the available type declarations in order to improve their 
optimisation capabilities as well.

CPython, specifically, can also continue to use a multi-step implementation 
as it's currently being done, i.e. split the implementation into a pure 
Python module with optional compilation, a Cython-specific partial 
reimplementation in optimised only-mostly-Python code, and potentially a C 
module for the external code that must really be implemented in pure C for 
whatever reason. That would already lower the entry level for non-C-affine 
contributors by moving more code into plain Python and (mostly Python) 
Cython code, instead of requiring proficiency in both C and CPython's C-API 
in order to work on the code at all.

Stefan



More information about the Python-Dev mailing list