EuroPython 2017

Optimizing Python code with Cython

Speaker(s) Andrew Svetlov

Many people heard about speeding up CPython code by writing C Extensions but almost nobody did it.

Writing bare C code is very hard and error prone, that’s why much easier and safer Cython was born.

This Python-like language allows to write C Extensions without managing reference counting and exception handling manually, Cython code is comparable with Python from clearness and readablity perspective but might be tens times faster.

But cythonizing the whole programm is redundant, mindless optimization doesn’t give any significant speedup but increases build toolchain complexity.

In the training we’ll learn the procedure step by step from very beginning down to real world use cases.

The talk is covering the following topics: * Problem detection aka bottleneck finding * Testing * Writing Cython optimizations for several common scenarios * Approaches for compiling and running * Tooling (profiling, debugging, coverage reporting)

We’ll consider optimization of the following very typical domains (from easier to harder): * Simple Mathematics * Standard Python data structures * Custom data structures

Every example is started from non-optimized Python code and goes through several transformations to high speed Cython’ed extension.

The session pursuites teaching people to optimizing existing Python Code, bridging to exisiting C libraries is another very interesting topic which is out of scope, sorry.

in on Wednesday 12 July at 10:15 See schedule

Comments

  1. Gravatar
    Have heard a lot about Cython, but never tried. What do you think of its applications on robotics, where efficiency and real-time is so important? And, if Cython is way better than the conventional Python interpreter, does it mean that the latter will become deprecated soon?
    — Alejandro Solano Rueda,

New comment