GC Isolates
#123089
Replies: 1 comment 5 replies
-
|
A NativeAOT module will have its own GC heap and isolated object references. It only pauses threads known to the module.
This is not possible. A foreign GC heap is effectively a foreign native module. It can only be interact with (in-process) interop. |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
Modern C# makes it possible to write high-performance, low-latency code. This requires pre-allocating as much as possible during initialization and then making zero allocations on the heap by using techniques like object pooling, stackalloc, Span<T>, ref structs, etc, to avoid triggering the GC.
The problem is that when carefully written zero-allocation code with low-latency requirements needs to be a part of a larger application, the no-allocation constraint propagates to the entire managed process. Zero-allocation techniques are feasible in individual components, but they become cost-prohibitive at application scale because allocations must be avoided even in modules that aren’t latency-sensitive.
Proposal
Add an ability to create GC-isolated threads that run on an isolated managed heap with its own GC, so GC pauses in the rest of the process don’t affect latency-sensitive work in the isolated thread. Any threads spawned from isolated thread inherit the same isolated heap and GC.
Like Dart isolates, C# GC isolates would use separate heaps with no shared object references, but here the goal is isolating GC pauses for low-latency threads in the same process, ideally with zero-copy ownership transfer between isolates.
Benefits
Practical example
OwnAudioSharp audio framework had to switch to C++, even though it was initially developed as a fully managed C# version that didn’t allocate and performed well. Because currently, any application using a managed audio engine also has to avoid allocations across the entire application to prevent GC pauses from affecting the audio thread.
Summary
This proposal would enable us to put a latency-sensitive component into a GC isolate, insulating it from STW collections happening elsewhere in the app.
Would something like this be technically feasible?
Beta Was this translation helpful? Give feedback.
All reactions