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

Temporarily immortalize objects that use deferred reference counting #117783

Closed
colesbury opened this issue Apr 11, 2024 · 2 comments
Closed

Temporarily immortalize objects that use deferred reference counting #117783

colesbury opened this issue Apr 11, 2024 · 2 comments
Labels
topic-free-threading type-feature A feature request or enhancement

Comments

@colesbury
Copy link
Contributor

colesbury commented Apr 11, 2024

Feature or enhancement

Work is ongoing to implement deferred reference counting in the free-threaded build. The goal is to avoid many of the scaling bottlenecks caused by reference count contention. However, the work is complex and may not be finished in time for the 3.13 beta release and feature freeze.

In the meantime, we should temporarily immortalize objects that would use deferred reference counting in order to avoid bottlenecks that would inhibit scaling.

This has some real downsides: objects that are immortalized are never collected so an application that repeatedly creates many of these objects will leak memory. I think the trade-off is still worth it: if we can't scale multithreaded programs, then the free-threaded build is not particularly useful.

Once we implement deferred reference counting, we will get rid of this.

What types of objects use deferred reference counting?

  • Top-level functions
  • Descriptors
  • Modules and their dictionaries
  • Heap types
  • Code objects

Refleak buildbots

We want the free-threading refleak buildbots to continue to work and catch leaks. In order to do that, we'll want to:

  1. Only do the deferred -> immortal conversion when the first non-main thread is started
  2. Disable the conversion at runtime in the refleak tests via an internal API

Linked PRs

@colesbury colesbury added type-feature A feature request or enhancement topic-free-threading labels Apr 11, 2024
colesbury added a commit to colesbury/cpython that referenced this issue Apr 12, 2024
colesbury added a commit to colesbury/cpython that referenced this issue Apr 19, 2024
…ting

Deferred reference counting is not fully implemented yet. As a temporary
measure, we immortalize objects that would use deferred reference
counting to avoid multi-threaded scaling bottlenecks.

This is only performed in the free-threaded build once the first
non-main thread is started. Additionally, some tests, including refleak
tests, suppress this behavior.
colesbury added a commit to colesbury/cpython that referenced this issue Apr 19, 2024
…ting

Deferred reference counting is not fully implemented yet. As a temporary
measure, we immortalize objects that would use deferred reference
counting to avoid multi-threaded scaling bottlenecks.

This is only performed in the free-threaded build once the first
non-main thread is started. Additionally, some tests, including refleak
tests, suppress this behavior.
colesbury added a commit to colesbury/cpython that referenced this issue Apr 19, 2024
colesbury added a commit that referenced this issue Apr 29, 2024
…118112)

Deferred reference counting is not fully implemented yet. As a temporary
measure, we immortalize objects that would use deferred reference
counting to avoid multi-threaded scaling bottlenecks.

This is only performed in the free-threaded build once the first
non-main thread is started. Additionally, some tests, including refleak
tests, suppress this behavior.
@colesbury
Copy link
Contributor Author

This is implemented now

colesbury added a commit to colesbury/cpython that referenced this issue Jun 1, 2024
The free-threaded build currently immortalizes objects that use deferred
reference counting (see pythongh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
colesbury added a commit that referenced this issue Jun 3, 2024
The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
colesbury added a commit to colesbury/cpython that referenced this issue Jun 3, 2024
)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see pythongh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.

(cherry picked from commit 47fb432)
colesbury added a commit that referenced this issue Jun 3, 2024
#120005)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see gh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.

(cherry picked from commit 47fb432)
mliezun pushed a commit to mliezun/cpython that referenced this issue Jun 3, 2024
)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see pythongh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
barneygale pushed a commit to barneygale/cpython that referenced this issue Jun 5, 2024
)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see pythongh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see pythongh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
)

The free-threaded build currently immortalizes objects that use deferred
reference counting (see pythongh-117783). This typically happens once the
first non-main thread is created, but the behavior can be suppressed for
tests, in subinterpreters, or during a compile() call.

This fixes a race condition involving the tracking of whether the
behavior is suppressed.
@terryjreedy
Copy link
Member

Immortalization has been removed in 3.14 #124239 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-free-threading type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants