The free-threaded build · Part 2 of 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.

Elliot Sayer4 min read

The number attached to the free-threaded build is 5 to 10% single-threaded overhead, quoted without a workload. That makes it unusable for a decision, because the overhead comes from biased reference counting and per-object locking, and those land on operations rather than on programs.

Eight operations, both builds of one version, same machine, same compiler. The ratios run from 0.98x to 1.37x.

Operation by operation

$ python3 experiments/freethread/singlethread.py \
    ~/.pyenv/versions/3.15.0rc1/bin/python3 \
    ~/.pyenv/versions/3.15.0rc1t/bin/python3
ns per operation, best of 7 rounds of 300,000

operation                        3.15.0rc1 GIL 3.15.0rc1 free-threaded    ratio
allocate an object                      90.91                 105.94    1.17x
read an attribute                        9.21                  10.95    1.19x
write an attribute                       9.94                   9.77    0.98x
set a dict key                          19.71                  23.50    1.19x
read a dict key                         22.21                  25.54    1.15x
append to a list                        15.66                  18.68    1.19x
add two integers                        24.00                  27.85    1.16x
sum over a range                         6.32                   8.65    1.37x

spread across the eight: 0.98x to 1.37x

Six of the eight sit between 1.15x and 1.19x, which is tighter than the spread suggests and higher than the quoted 5 to 10%. The two rows outside that band are the interesting ones.

The attribute write that got faster

write an attribute came out at 0.98x — the free-threaded build measuring marginally quicker than the GIL build at the same job. Nothing in the free-threaded design makes a store cheaper, so the honest reading is that this is the harness’s noise floor: about 2%.

That matters more than it looks. A 1.17x row measured by an instrument whose floor is 2% is a real 17%. If the floor had been 15%, none of the middle rows would mean anything, and the entry would be reporting the harness rather than the build.

The row that should have been free

sum over a range is the largest ratio in the table at 1.37x, and it was included on the expectation that it would be the smallest. The reasoning was that a single call from Python into C spends its time inside one C function, where the interpreter’s per-operation costs have nowhere to land.

That reasoning is wrong, and the row is where it fails. sum(range(300000)) walks three hundred thousand integer objects and adjusts a reference count on every one of them. Reference counting is exactly what free threading made more expensive, and it does not care which side of the C boundary it happens on.

The general form: the tax follows object touches, not Python bytecode. An extension that processes a large array of C doubles pays nothing; an extension that iterates a list of Python objects pays the same rate as the interpreter does.

PEP 703 says which mechanism that is. It names “biased reference counting” — each object has an owning thread, which uses non-atomic operations while other threads use atomic ones — and puts it first in the cost list: “the largest contribution to execution overhead is biased reference counting followed by per-object locking”. Its own measured figure for one thread is 6% on Intel Skylake and 5% on AMD Zen 3, which is where the quoted 5 to 10% comes from.

Those two numbers are the whole benchmark suite averaged. The eight rows here are individual operations chosen because they touch objects constantly, so 15 to 19% is what the expensive end of that average looks like when it is not averaged. Both are true; they answer different questions.

What this leaves for a decision

Take the split. A service that spends 90% of its CPU on single-threaded request handling and 10% on something that could be parallel is looking at roughly 15 to 20% more CPU on the 90%, against the 4.4x to 7.7x the previous entry measured on the other 10%.

Whether that trade is worth taking is arithmetic on a specific workload, and the two numbers to put into it are on this page and the last one. What cannot be done is applying either as a general figure: the parallel win is bimodal on the hardware, and the single-threaded loss varies by a factor of 1.4 across ordinary operations.

The rows to weight most heavily are allocation and container mutation, because those are the ones a request handler does constantly and the ones carrying 1.15x to 1.19x here. Allocation is also the operation whose cost depends most on what shape the object has, so a service built out of slotted rows and one built out of dict-backed ones are not paying the same 1.19x.

Allocation is the row worth singling out. At 90.91 ns against 105.94, one object costs 15 ns more, and a request that builds ten thousand objects — a serialised response of any size does that — has spent 150 microseconds on the difference before it has done anything. That is small next to a database round trip and large next to the request’s own Python time, which is the shape of most of these decisions.

Where to stop

One machine, Apple M4 Pro, macOS. CPython 3.15.0rc1 built twice by pyenv on 2 September 2026, one with the GIL and one without. The final 3.15 is dated 1 October.

Every measurement is single-threaded and uncontended: one thread touching objects that no other thread has a reference to. That is the cheapest case for per-object locking, so these figures are the floor of the cost, not the whole of it. A multi-threaded service pays this plus whatever the locking costs under contention, and this harness says nothing about the second part.

The noise floor is about 2%, established by the one row that moved the wrong way. Ratios inside that band are not findings.

Frequently asked

Is the quoted 5 to 10% wrong?

It is low for this workload set. Six of the eight operations here land between 1.15x and 1.19x, which is 15 to 19%. The quoted range may well be right for the benchmark suites it came from — the point is that a percentage without a workload cannot be applied to a service, and these eight rows are also a workload rather than a verdict.

Why does a single call into C pay the most?

Because the call being a single Python-level operation says nothing about what happens inside it. sum(range(n)) walks n integers and adjusts a reference count on each one, and reference counting is exactly what the free-threaded build made more expensive. The row is a reminder that "it is in C" is not the same as "it does not touch objects".

Which operations would make this worse for a real service?

The ones this harness runs single-threaded and uncontended. Every measurement here has one thread touching objects nobody else touches, which is the cheap path for per-object locking. A service with several threads reading the same objects pays for the locking as well as for the counting, and nothing here measures that.

Does this cancel out the parallel win?

It depends entirely on the split. A service that is 90% single-threaded and 10% parallel pays 15 to 20% on the 90% to gain somewhere between 4.4x and 7.7x on the 10%, which is a clear win in wall time and a clear loss in cost per request on the sequential part. The arithmetic is a decision about a specific workload, not a general answer.

Where this came from

Run it yourself — every figure above came out of these:

  1. freethread/singlethread.py — Single-threaded cost of the free-threaded build

Read, rather than assumed:

  1. PEP 703 — Making the Global Interpreter Lock Optional in CPython
Share

Arrow keys to move, Enter to open.