Use per-thread freelists in `--disable-gil` builds

Skip to content

Navigation Menu

Sign in

Appearance settings

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

Closed

@colesbury

Description

Feature or enhancement

CPython uses freelists for frequently allocated Python objects, like dict, list, and slice. There freelists are generally stored in the per-interpreter state, which is not thread-safe without the GIL. In --disable-gil builds, the freelists should be stored in the per-thread state (i.e., PyThreadState). I think we probably want to keep the freelists in the interpreter state for the default build. This will probably require some refactoring.

Freelists:

  • float
  • slice (slice_cache)
  • tuple
  • list
  • dict (PyDictKeysObject and PyDictObject)
  • generator (value_freelist and asend_freelist)
  • PyContext

For context, here are similar changes in the nogil-3.12 fork, but I expect the changes in CPython 3.13 to be a bit different:

Linked PRs

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions