What's new in Cython 0.25?
Cython 0.25 has been released in October 2016, so here's a quick writeup of the most relevant new features in this release.
My personal favourites are the call optimisations.
Victor Stinner has done a great job throughout the year to optimise and benchmark different parts of CPython, and one of the things he came up with was a faster way to process function calls internally.
For this, he added a new calling convention, METH_FASTCALL, which avoids tuple creation by passing positional arguments as a C array.
I've added support for this to Cython and also ported a part of the CPython implementation to speed up calls to Python functions and PyCFunction
functions from Cython code.
Further optimisations speed up f-string formatting, cython.inline()
and some Python long integer operations (now also in Py2.7 and not only Py3).
The next big feature, one that has been on our list essentially forever, was finally added in 0.25.
If you declare a special attribute __dict__
on a cdef class
(a.k.a. extension type), if will have an instance dict that allows setting arbitrary attributes on the objects.
Otherwise, extension types are limited to the declared attributes and trying to access undeclared ones would result in an AttributeError
.
The C++ integration has received several minor improvements, including support for calling subclass methods from C++ classes implemented in Cython code,
iterating over std::string
with Cython's for-loop, typedef
members in class declarations, or the typeid
operator.
And a final little goodie is redundant declarations for pi
and e
in libc.math
, which makes from libc cimport math
pretty much a drop-in replacement for Python's import math
.