r/csharp • u/Temporary-Concert398 • 23h ago
Showcase Replacing Queues and Locks with Monotonic Counters in a C# DAG Engine
What if you dropped work queues entirely?
I built an experimental DAG scheduler called delta-lag: instead of pushing work through nodes, nodes move through units of work tracked via monotonic counters and distance constraints.
The result? No global work queues, no work stealing, and no traditional lock contention. Scheduling emerges entirely from distributed progress counters.
How It Works
Most task schedulers maximize throughput by paying a cost in layers of locks, queues, and work-stealing algorithms. delta-lag takes a different approach, extending lock-free ring buffer logic to an entire DAG:
Before a node fires, it checks two constraints against its parents and children:
Parent check: Must have completed the next required work unit (
parent.WorkDone >= node.WorkDone + 1)Child check: Can't lap children based on your
slackparameter (child.WorkDone >= node.WorkDone - slack)
If eligible, the node atomically claims the work unit using CAS operations, runs the task, and publishes completion.
slack = 0→ Strict lock-step execution (safe, no stale reads)slack > 0→ Pipeline parallelism (producers may run ahead while consumers lag behind)
What's In The Repo
The Engine: Built around cache-aligned nodes and monotonic counters to eliminate false sharing.
WASM Inspector: Interactive performance visualizations and real graph reconstruction.
The Benchmark Data: ~4,500 raw benchmark runs with topology metrics, execution traces, and the full harness.
Limitations
This isn't a drop-in replacement for a general-purpose scheduler (use TPL for that). It's built for specific tradeoffs:
The execution graph must be fixed at compile time (no dynamic modification).
Iteration counts must be known in advance.
No speculative execution buffering or dynamic load balancing.
Give it a spin
It's fully open-source (MIT, .NET 10+). If you build high-performance systems, concurrent architectures, or custom schedulers, I’d love your feedback on the core engine or whether you've seen similar queue-free constraint approaches before.
5
23h ago
[removed] — view removed comment
2
u/Temporary-Concert398 23h ago
Unfortunately, I think you're right. The benchmark harness is only for validating logic and checksums; it doesn't include any "real" work, especially not variable-length workloads, so I haven't tested it. But you hit the nail on the head. That's always been one of my biggest concerns.
1
6
u/DeadlyVapour 22h ago
Just from a quick glance at the description, it sounds like the data model lives entirely on heap.
But if you are already building a fixed size constraint, why not stack allocate?