Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-110481: Implement biased reference counting #110764

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

colesbury
Copy link
Contributor

@colesbury colesbury commented Oct 12, 2023

CPython's current reference counting implementation would not be thread-safe without the GIL. This implements biased reference counting in --disable-gil builds, which is thread-safe and has lower execution overhead compared to plain atomic reference counting. The design is described in the "Biased Reference Counting" section of PEP 703.

Removing the trailing comma allows the macros to be used in more places,
which means fewer `#ifdef Py_NOGIL` checks.

Note that the public API macros `PyObject_HEAD_INIT` and
`PyVarObject_HEAD_INIT` are not changed.
@colesbury
Copy link
Contributor Author

Note for reviewer: the first commit in this PR refactors the internal-only _PyObject_HEAD_INIT macro to not have a trailing comma, which avoids the need for a number of #ifdef Py_NOGIL in the subsequent commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant