Jukka Lehtosalo

Jukka is the creator of the mypy static type checker, and the co-author of PEPs 484 (which introduced standardized type hints to Python), PEP 544, PEP 586 and PEP 589. He is one of the founders of typeshed. Jukka works as a Staff Engineer at Dropbox. He is currently leading the mypyc compiler project and optimizing the efficiency of production Python services at Dropbox.


Session

07-17
12:25
30min
Speeding Up Python with Free Threading and Mypyc
Jukka Lehtosalo

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.

Python Core, Internals, Extensions
Auditorium Hall (S1)