conferences | speakers | series

Rusty Python: A Case Study

home

Rusty Python: A Case Study
PyCon DE & PyData Berlin 2023

Python is a very expressive and powerful language, but it is not always the fastest option for performance-critical parts of an application. Rust, on the other hand, is known for its lightning-fast runtime and low-level control, making it an attractive option for speeding up performance-sensitive portions of Python programs. In this talk, we will present a case study of using Rust to speed up a critical component of a Python application. We will cover the following topics: * An overview of Rust and its benefits for Python developers * Profiling and identifying performance bottlenecks in Python application * Implementing a solution in Rust and integrating it with the Python application using PyO3 * Measuring the performance improvements and comparing them to other optimization techniques Attendees will learn about the potential for using Rust to boost the performance of their Python programs and how to go about doing so in their own projects.

# Context In the past, C and C++ were the go-to languages for optimizing Python code while still maintaining a high-level interface. This approach was used by well-known numerical libraries such as Numpy and Pandas. However, with the increasing popularity of Rust and the emergence of PyO3, this is no longer the only solution available. Rust's impressive performance and expressive syntax, combined with its comprehensive library ecosystem, make it a viable alternative for optimizing performance-sensitive parts of Python applications. Additionally, Rust's mature support for asynchronous programming gives it an advantage over C foreign function interfaces when interacting with Python coroutines. Some library maintainers are even considering using Rust for their projects, such as Pydantic, which is implementing version 2 in Rust and achieving similar speed improvements to those obtained using C. # Timeplan In minutes * 0-2: Welcome, explanation of title * 2-7: What is Rust and how is it different to other "bare metal" languages * 7-10: Introducing the case study, running the code, getting feel for performance * 10-15: Code profiling, finding of bottle neck * 15-17: Introducing PyO3 * 17-22: Walking through the Rust code that optimizes the bottle neck * 22-25: Running the code live, showing the speedup * 25-28: Mention extensions provided by PyO3, caveats and what code might not be a good goal to optimize. Mention tradeoffs to other foreign function interfaces. * 28-30: Buffer / Q&A

Speakers: Robin Raymond