Speeding Up Python with Free Threading and Mypyc
- Track:
- Python Core, Internals, Extensions
- Type:
- Talk
- Level:
- advanced
- Duration:
- 30 minutes
Abstract
It’s common to hear complaints about Python being slow. In this talk, I will show how to make some Python programs dramatically faster by using Python 3.14’s free threading and ahead-of-time compilation to C extensions using the mypyc compiler, while staying entirely in Python (and CPython).
Free threading can deliver large speedups for CPU-bound code that can be adapted for parallel execution, while mypyc speeds up workloads that benefit from reduced interpreter overhead and that can use static typing. If each can give a 10x speedup in an ideal use case, can we get a “holy grail” 100x speedup by using both?
I’ll introduce several small examples inspired by real-world workloads, measuring and explaining what happens when you apply free threading, mypyc, or both. In practice, relatively few programs are perfect fits for both techniques at once, but when they are, you can get substantial gains. Having both tools available gives you options for attacking a wide range of performance problems.
Along the way, I’ll cover various bottlenecks you are likely to encounter while optimizing real-world workloads. These often limit performance scaling. I'll explain how to diagnose and improve allocation-heavy code and thread contention caused by reference counting, in particular.