GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Use deferred reference counting in some `_PyInterpreterFrame` fields · Issue #123923 · python/cpython

Use deferred reference counting in some _PyInterpreterFrame fields #123923

New issue
Copy link
New issue
Copy link
Closed
Closed
Use deferred reference counting in some _PyInterpreterFrame fields#123923
Copy link
Labels
topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

Description

@colesbury
colesbury
opened on Sep 10, 2024
Issue body actions

Feature or enhancement

The _PyInterpreterFrame struct contains a strong reference to:

  • f_executable - the currently executing code object
  • f_funcobj - the function object
  • f_locals - the locals object (often NULL)
  • frame_obj - the frame object (often NULL)

We should use deferred references (in the free-threaded build) for f_executable and f_funcobj because they are a common source of reference count contention. The pointed to objects (code and function) already support deferred reference counting, but the references in the frame are not deferred.

I think we don't need to bother with changing f_locals for now. I don't think it's used frequently enough to be a bottleneck, but we can revisit it later if necessary.

The frame_obj are typically unique -- not shared across threads -- so we don't need to bother with deferred reference counting for frame_obj.

Complications and hazards

_PyInterpreterFrame are also embedded in generators/coroutines and PyFrameObject, which are heap objects. We need to be careful that _PyStackRef fields are visible to the GC in order to be kept alive. Once an object is untracked, the _PyStackRef fields may no longer be valid: it's safe to call PyStackRef_CLOSE/CLEAR but not otherwise access or dereference those fields because the GC may have already collected them.

Linked PRs

  • gh-123923: Defer refcounting for f_executable in _PyInterpreterFrame #123924
  • gh-123923: Defer refcounting for f_funcobj in _PyInterpreterFrame #124026

Activity

  1. colesbury
    added
    type-featureA feature request or enhancementA feature request or enhancement
    topic-free-threading
    on Sep 10, 2024
  2. colesbury
    added 9 commits that reference this issue on Sep 10, 2024

    pythongh-123923: Defer refcounting for `f_executable` in `_PyInterpre…

    371d6c7

    pythongh-123923: Defer refcounting for `f_executable` in `_PyInterpre…

    24e9b4b

    gh-123923: Defer refcounting for `f_executable` in `_PyInterpreterFra…

    b2afe2a

    pythongh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreter…

    5552fa6

    pythongh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreter…

    db12634

    Merge branch 'main' into pythongh-123923-defer-func

    68d360e

    Merge branch 'main' into pythongh-123923-defer-func

    6a1014f

    Merge branch 'main' into pythongh-123923-defer-func

    2fde56d

    gh-123923: Defer refcounting for `f_funcobj` in `_PyInterpreterFrame` (…

    f4997bb
  3. colesbury
    closed this as completedon Oct 1, 2024
  4. taegyunkim
    added a commit that references this issue on Dec 11, 2025

    feat(profiling): support Python 3.14 (#15546)

    1823291
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic-free-threadingtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.