Runtimev0.3.1

dtact

The universal topology-affinity async runtime

MIT OR Apache-2.0Rust · C · C++x86_64 · AArch64 · RISC-V
0.19 µs
Per task at N=1,000
spawn + join
5.4×
Cheaper than Tokio
same benchmark
7
Spawn-time knobs
priority · affinity · kind
3
Architectures
x86_64 · AArch64 · RISC-V

Overview

dtact is a non-preemptive, stackful coroutine runtime. Instead of compiling async code into state machines, it gives every task its own stack and switches between them with hand-written assembly. That one decision makes the rest possible: a suspended task keeps its C stack, so foreign code can suspend and resume it.

Scheduling is a peer-to-peer mesh rather than a global work-stealing queue. Workers exchange work through bounded lock-free mailboxes, so a saturated core deflects its backlog into a neighbouring cache domain instead of contending on one shared structure.

Contexts are carved out of a pre-allocated arena, which turns spawning into an index allocation, and futures small enough to fit are placed on the fiber's own stack. The project is explicit about the trade-off: a yield is a full register switch, heavier than a stackless runtime, and worth it when the work between yields is substantial or when C has to participate.

Capabilities

what it does

Lock-free context arena

Fiber contexts come from a pre-allocated arena, so spawning is an index allocation rather than a heap allocation — even at high spawn rates.

P2P mesh scheduling

Workers exchange work through bounded, lock-free mailboxes instead of one global work-stealing queue, which keeps contention local to a cache domain.

Topology-aware affinity

SameCore, SameCCX, SameNUMA or Any: deflection is confined to the neighbourhood you choose, per runtime or per fiber.

Assembly context switchers

Hand-written switchers per architecture, with floating-point and cross-thread variants, so the cost of a switch matches the workload.

Zero-copy futures

Small and medium futures are placed directly on the fiber's own stack, removing a heap allocation from the spawn path.

C and C++ FFI

Fibers have their own stacks, so C code can launch and await them. dtact-util exposes io, fs, process, signal, stream and timer through the same ABI.

How it works

design notes
01

The spawn path

A spawn takes a slot from the context arena, writes the future into the slot's zero-copy buffer and publishes the handle. There is no allocator call and no queue insertion on the critical path.

02

Deflection instead of stealing

A full mailbox hands work to a neighbour rather than waiting: each worker pushes to peers and pulls only from its own mailbox, so contention stays inside a cache domain.

03

Affinity that is enforced

SameCore pins, SameCCX and SameNUMA confine deflection, Any lets work travel. P2PMesh, Global and Pinned set the runtime default; topology_mode overrides it per fiber.

04

Priorities with consequences

Low and High bias the deflection threshold. Critical is never deflected, enters at the front of its worker's queue, and parks rather than migrating when the queue is full.

05

Per-architecture switchers

Assembly context switches for x86_64, AArch64 and RISC-V, with variants that skip floating-point state or switch across threads — you pay for the state you need.

06

Stack safety levels

Safety0 performs no overflow check, Safety1 checks a canary at termination, Safety2 checks at every suspension. Trips are counted, and named fibers appear in diagnostics.

Measured performance

project benchmarks
Criterion benchmarks from benches/scheduler_efficiency.rs: 4-core x86_64, 4 workers per runtime, 50 samples of 5 s after a 2 s warm-up. Per-task cost is total time divided by N, read from the published charts.
WorkloaddtactNote
Spawn + join, N = 1,000≈195 ns per task≈5.3× cheaper than Tokio
Spawn + join, N = 100,000≈450 ns per taskadvantage narrows with batch size
Hot-core deflectionahead at both extremesdips near N ≈ 4,000–16,000
Yield costfull register switchstackful by design — amortise the work
Two charts: per-task spawn and join cost in nanoseconds for dtact and Tokio from N=1,000 to 100,000, and the ratio between them.
Spawn + join: median per-task cost in nanoseconds, and Tokio's cost divided by dtact's. Above 1.0 means dtact is faster.

Install

cargo
shell — cargo
# the runtime
cargo add dtact

# async I/O on the same scheduler
cargo add dtact-util

The C API ships as dtact.h; dtact-util exposes io, fs, process, signal, stream and timer through the same ABI, with io_uring, IOCP and kqueue backends.