]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-131586: Avoid refcount contention in some "special" calls (#131588)
authorSam Gross <colesbury@gmail.com>
Wed, 26 Mar 2025 18:38:47 +0000 (14:38 -0400)
committerGitHub <noreply@github.com>
Wed, 26 Mar 2025 18:38:47 +0000 (14:38 -0400)
commit67fbfb42bd5dfe861d0c58d9e6c48d8eef033d24
tree282178fa55571c055c8327dc3d77fa6a882a404b
parent3d4ac1a2c2b610f35a9e164878d67185e4a3546f
gh-131586: Avoid refcount contention in some "special" calls (#131588)

In the free threaded build, the `_PyObject_LookupSpecial()` call can lead to
reference count contention on the returned function object becuase it
doesn't use stackrefs. Refactor some of the callers to use
`_PyObject_MaybeCallSpecialNoArgs`, which uses stackrefs internally.

This fixes the scaling bottleneck in the "lookup_special" microbenchmark
in `ftscalingbench.py`. However, the are still some uses of
`_PyObject_LookupSpecial()` that need to be addressed in future PRs.
16 files changed:
Include/internal/pycore_global_objects_fini_generated.h
Include/internal/pycore_global_strings.h
Include/internal/pycore_object.h
Include/internal/pycore_runtime_init_generated.h
Include/internal/pycore_stackref.h
Include/internal/pycore_structs.h
Include/internal/pycore_tstate.h
Include/internal/pycore_unicodeobject_generated.h
Lib/test/test_bool.py
Lib/test/test_builtin.py
Lib/test/test_math.py
Modules/mathmodule.c
Objects/object.c
Objects/typeobject.c
Python/bltinmodule.c
Python/gc_free_threading.c