Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement biased reference counting in--disable-gil builds #110481

Closed
Assignees
colesbury
Labels
3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement
@colesbury

Description

@colesbury

Feature or enhancement

CPython's current reference counting implementation would not be thread-safe without the GIL. In--disable-gil builds, we should implement biased reference counting, 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.

This will require changing thePyObject struct in--disable-gil builds. I expect the--disable-gil struct to look like:

struct_object {uintptr_tob_tid;uint16_t_padding;uint8_tob_mutex;uint8_tob_gc_bits;uint32_tob_ref_local;Py_ssize_tob_ref_shared;PyTypeObject*ob_type;};

Not all the fields will be used immediately, but it will be easier to include them as part of implementing this change.

I intend to split the implementation across (at least) two PRs to make it easier to review.

  1. The first PR will add the newPyObject fields and implement the core biased reference counting operations, but not theinter-thread queue to reduce the initial complexity. (done)
  2. A later PR will implement the inter-thread queue. (not yet implemented)

The inter-thread queue is needed eventually (beforeactually disabling the GIL), but since the--disable-gil builds still currently require the GIL, it doesn't have to be in the initial PR.

Linked PRs

Metadata

Metadata

Assignees

Labels

3.13bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp