Offline

Python Dicts: Past, Present, and Free-Threaded Future

Track:
Python Core, Internals, Extensions
Type:
Talk
Level:
advanced
Duration:
30 minutes
View in the schedule

Abstract

Python dicts are everywhere! They back module namespaces, instance attributes, **kwargs, and of course actual dictionaries. But have you ever wondered how they work under the hood? And more importantly, what happens to them now that free-threaded Python is here?

In this talk, we'll start by exploring the internals of CPython's dict implementation: how hashing works, the compact table layout that gives you insertion order, and how lookups, insertions, and deletions actually play out in memory. Then we'll see what had to change for free-threading: how reads remain fast without acquiring locks, what the per-object lock is and when it kicks in, and why making a dict thread-safe is harder than it sounds.

Finally, we'll look at the ongoing effort to document CPython's thread-safety guarantees for built-in types and what the resulting documentation means for a Python developer writing concurrent code.

The audience will leave with a deep understanding of how Python's most important data structure works, how it's been adapted for a free-threaded world, and what they can (or can't) safely do with dicts across threads.