Bug report
On the free-threaded build, thread_local_read in Tools/ftscalingbench/ftscalingbench.py regressed sharply between 3.15.0a8 and main. git bisect between v3.15.0a8 and 04fd103713a identifies 8923ca4 as the first bad commit.
Measurements (10 threads, Apple Silicon, free-threaded)
| Python |
thread_local_read |
| 3.14.4t |
3.6× faster |
| 3.15.0a8 |
3.7× faster |
| parent of 8923ca4 |
3.7× faster |
| 8923ca4 |
11.9× slower |
| main @ 04fd103 |
10.8× slower |
Root cause
The commit changed PyType_GetModuleByDef (Objects/typeobject.c:5892) which added a incref/decref which causes significant ref counting contention.
// before: genuinely borrowed, no refcount ops
return borrow_module_by_token(type, def);
// after: Py_NewRef inside PyType_GetModuleByToken, then immediate Py_XDECREF
PyObject *mod = PyType_GetModuleByToken(type, def);
Py_XDECREF(mod);
return mod;
Linked PRs
Bug report
On the free-threaded build,
thread_local_readinTools/ftscalingbench/ftscalingbench.pyregressed sharply between 3.15.0a8 andmain.git bisectbetweenv3.15.0a8and04fd103713aidentifies 8923ca4 as the first bad commit.Measurements (10 threads, Apple Silicon, free-threaded)
thread_local_readRoot cause
The commit changed
PyType_GetModuleByDef(Objects/typeobject.c:5892) which added a incref/decref which causes significant ref counting contention.Linked PRs
PyType_GetModuleByDefon free-threading #148908