Category 02
Concurrency
What is actually parallel, and what the scheduling costs. Threads, the GIL, free threading, asyncio, subinterpreters and processes.
- Entries
- 4
- Series
- 2
Free Threading Costs One Thread Between 0.98x and 1.37x
The quoted single-threaded overhead is 5 to 10%. Measured operation by operation on one version's two builds, it runs from nothing on an attribute write to 37% on a sum.
Eight Threads Scale 4.42x or 7.66x, and Nothing In Between
On the free-threaded build the same binary scales eight CPU-bound threads to between 4.42x and 7.66x across seven runs. On the GIL build the same row is 0.96x.
The Real Cost of an async Call
Awaiting a coroutine that never suspends costs 53 ns against 24 ns for a plain call. Wrapping the same coroutine in a Task and awaiting it costs 28,958 ns.
The GIL Is Not a Lock on Your CPU
Eight threads of pure-Python arithmetic run at 0.98x the speed of one. The same eight threads doing IO run at 7.90x. The GIL is a scheduler, and it has a dial.