Posters: From 3 to 300 fps: NES Emulation in Python and Cython

Presented by:


Description

It is sometimes asserted that “Python is a real bad choice for any kind of real-time system”. When I first got my Python NES emulator to boot, only for it to run at 2 frames per second, I felt like agreeing. But is it really true? After just a few days reworking the emulator’s operational core into Cython, the framerate is now above 300fps, proving that Python is a viable choice for emulator development and other performance-dependent projects. This poster looks at the advantages and some challenges of using Cython to achieve realtime performance from an existing Python codebase.

For Python projects, Cython fits with the golden rule of optimization: only do what needs doing! It’s easy to optimize correct code, but it’s hard to correct optimized code, so try to do as little as possible. Cython beautifully allows this in Python projects by letting you move code from Python to Cython piece by piece, down to the level of functions or class methods, while still retaining existing code structure, and interoperability. In addition, systems projects like emulators involve lots of known data types, buses, memory and registers of fixed width, and Cython can actually help make some of that clearer than in Python