PyCon Sweden 2026

Immutability: Safe and Fast Sharing of Data Across Threads

Python is becoming more parallel with Free-Threading and Subinterpreters. Both approaches allow threads to run in parallel without the restriction of a single GIL. The downside is that parallelization comes with a safety tax: Free-threading adds a lock per object and subinterpreters typically involve pickling and copying data between interpreters to ensure isolation. This has a negative impact on performance with both CPU and memory overheads. This talk is about PEP795, which proposes to add immutability to Python. It allows threads to share data without the risk of data races. This enables different optimisations: on free-threaded Python, interpreter-level synchronisation is no longer needed to ensure safe access to shared data structures (think PEP frozendict but for any type), it allows multiple subinterpreters to directly share objects without copying, and it improves GC performance by simplifying cycle detection.

We will present the design and rationale for immutability in Python, the API for creating and managing immutable state, decorators for communicating immutability in code, as well as opting out of immutability where necessary. We will also discuss our prototype implementation on-top of Python 3.15 and demonstrate how immutable sharing across sub-interpreters improves performance and compare the speed of freezing (the act of making objects immutable) to pickling and unpickling.

This is an updated version of our immutability talk at EuroPython'26 based on feedback from the Python community.


Attendees will learn:

  • About the semantics of immutability in Python.
  • When immutability can improve performance and predictability in concurrent Python.
  • How freezing works for built-in types, user‑defined types and functions.
  • Performance of pickling vs. immutable sharing, with numbers and failure modes.
  • Current limitations of immutability, risks, and what would need to land in CPython for this to be widely usable. Target audience: programmers interested in concurrent programming in Python.

Note: This PEP is not yet accepted; the talk focuses on design, prototype results, and open questions.

Fridtjof Stoldt

I'm a PhD student focussing on programming languages and compilers. Currently, I'm focussed on retrofitting concurrency to Python without breaking existing programs