druntime: opt-in thread-local GC (tgc) - #23514
Open
AMDphreak wants to merge 1 commit into
Open
Conversation
Introduce --DRT-gcopt=gc:tgc with per-thread heaps and local collection that avoids global stop-the-world pauses, for mixed GC/@nogc realtime work. Co-authored-by: Cursor <cursoragent@cursor.com>
AMDphreak
added a commit
to dlang-supplemental/docs
that referenced
this pull request
Aug 2, 2026
Cross-link the tgc announcement to the opened pull request. Co-authored-by: Cursor <cursoragent@cursor.com>
AMDphreak
added a commit
to dlang-supplemental/docs
that referenced
this pull request
Aug 2, 2026
* Add Blog and News sections with tgc design article Introduce Antora Blog/News (separate from Changelog) and publish the thread-local GC (tgc) concept post plus upstream announcement stub. Co-authored-by: Cursor <cursoragent@cursor.com> * Link news article to upstream dlang/dmd#23514 Cross-link the tgc announcement to the opened pull request. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
Author
Design write-up and announcement
Opt-in only via |
DMD perf check
|
Member
|
Interesting experiment, not sure how far you can get with that using the current D runtime, though. Note for example that immutable data (e.g. strings) is implicitly shared between threads and message passing often takes advantage of that. This results in cross-thread pointer references that can cause premature collection. One way to get an idea of how far this GC can be used is to enable it by default in this PR and check the results of the test suite. There are a couple of implementation details that might also need some work:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an opt-in thread-local garbage collector registered as
tgc(--DRT-gcopt=gc:tgc).Each attached thread owns a private heap arena. Collection scans/sweeps only that thread (stack, TLS, local blocks) and does not call
thread_suspendAll. Detached@nogcthreads remain unpaused. The default conservative GC is unchanged.Informal side-name in prose: "realtime GC". Registered name:
tgc.Motivation
D isolates TLS data and offers actor-style
std.concurrency, but the GC heap is still process-global. A collection anywhere stop-the-world pauses all registered threads, including pure@nogcrealtime workers. An opt-in per-thread collector lets mixed GC /@nogcapps keep predictable latency on critical threads.Usage
v1 limits
immutablemessage passing across threads.sharedGC pointers across heaps unsupported.druntime/test/gc/tgc.d); not a production realtime guarantee without further benchmarks.Design article
https://dlang-supplemental.github.io/docs/docs/blog/thread-local-gc-tgc.html
(Also: news stub https://dlang-supplemental.github.io/docs/docs/news/tgc-upstream-pr.html after docs deploy.)
Test plan
make -C druntimebuilds with new moduledruntime/test/gcincludingtgcwith--DRT-gcopt=gc:tgcon Windows