Cython speedups borrow from Python playbook

The newest edition of the powerful Python-to-C compilation framework adds speedups harvested from the next version of Python

What's faster than Python? C. What's also far less convenient than Python? C.

But for people who want the convenience of Python and the speed of C, the Cython toolkit incrementally converts Python code to C by adding static variable typing and other code annotation.

Cython 0.25 appeared late last week with a bevy of improvements that benefit Python developers translating their projects into C, as well as C/C++ developers looking to interoperate with Python.

Some of the most notable improvements come from Python itself -- specifically, the forthcoming Python 3.6, due this Christmas.

One key change slated to land in Python 3.6 is faster function-call performance. The changes aren't drastic, as off-the-cuff benchmarking shows, but every little bit helps.

Cython 0.25 employs this new function-call methodology in code generated by the toolkit, so any Python function calls made within a Cython module will be executed more quickly. Those improvements will show up even in Cython code built from Python 3.5 modules, but if you're running Python 3.6, the faster call methods will be used in regular (non-Cython) code as well.

Additionally, Cython code will speed up generating strings using Python's string-formatting functions or the cython.inline decorator that allows functions to be placed in the generated C code as an optimization.

It's also now possible to manually toggle off garbage collection in a code block with the cython.no_gc directive. Python's garbage collector allows you to not worry about the niceties of memory management, but not everyone wants it to run during performance-sensitive code; it's handy to have a contextual method to put it on hold in a Cython module.

Cython 0.25 rolls out more interactions with nonstandard Python runtimes that perform just-in-time compilation or other optimizations, and it's the first Cython version to support the use of Cython modules in Dropbox's Pyston interpreter. Python 3.6 is slated to include extensions to allow third-party JITs, which Microsoft contributed to the language; future additions to Cython are likely to start plugging into that feature once a few third-party JITs show up to take advantage of it.

Last but not least, Cython is following the lead of many other open source projects and is recentering its development and issue tracking on GitHub. That said, if you have a problem, do the developers a favor and ping them first by email rather than opening an issue -- there's a good chance your problem has a quick solution.

Copyright © 2016 IDG Communications, Inc.