louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
ADR 0004: Actor model and scheduler
Status: Accepted — 2026-10-08, reviewed and accepted by the project owner (issue #2), including Revision 1.
Context
The language needs OTP semantics:
- lightweight processes and message passing,
- links and monitors,
- supervisors and "let it crash",
- preemptive fairness, so a busy actor cannot starve the others.
This has to fit a statically typed language without a GC (ADR 0002).
Decision
Processes:
- Process = actor = fiber. Each actor runs on its own stack: mmap'd, with a guard page (provided by corosensei at first; the runtime's own since ADR 0011).
- Each actor owns its
tl_ctx.
Scheduler:
- v0 runs N scheduler threads (one per core). Each actor is pinned to one thread at spawn (round-robin).
- There is no work stealing in v0. Migration is v1, and the explicit-context ABI already allows it.
- Fiber stacks are never dropped while suspended.
Preemption: reduction counting. TL_ENTER at every function entry and loop back-edge costs one reduction, and the budget is 4000 reductions.
Process operations:
- They form a built-in effect
<proc>:spawn,send,receive,self,link,monitor,exit,trap_exits. - Because they are an ordinary effect, tests can handle
<proc>with a mock handler.
Typed messaging, following Gleam OTP:
- A
Subject<msg>is a pid plus a unique tag.send(subject, msg)type-checks the message. - A
Selector<a>combines several subjects, monitor DOWN messages and timeouts into a typed selectivereceive ... after. - Each kind of reply can therefore have its own type:
callreplies, DOWN messages, timer ticks.
Sending messages:
senddeep-copies the message into the receiver, using the self-describing headers (runtime ABI).- A forwarding table preserves sharing within the message.
- Closures copy correctly: the code pointer is raw and the environment is scanned.
Shared values:
- Large
Bytesandthread_safeFFI resources are not copied. They are promoted to shared, with an atomic count.
Send safety:
- Static: a
Sendauto-trait is checked onSubjectmessage types. ADTs are structural, function types are assumed Send, andResource<t>is Send only when declaredthread_safe. - Dynamic: a pinned header bit (non-thread-safe resources) makes the deep copy fail, and the sender crashes with a clear reason. The dynamic check exists because a closure's captured environment is invisible to the type checker.
Exits:
| How the actor ends | Mechanism | What linked actors see |
|---|---|---|
| Panic | PANIC unwinding | an abnormal exit signal |
| Exit signal | delivered at the next safe point (TL_ENTER slow path or receive), unwinds via KILL | — |
| Normal return | — | a normal exit |
Library code:
actor.start(gen_server-like, with typedcallandcast) andsupervisorare written in Louise instd.supervisorsupports one_for_one, one_for_all and rest_for_one, with restart intensity.
IO:
- A mio reactor per scheduler thread. Actors park on fd readiness, and timers use a timer wheel.
- FFI marked
blockingruns on one shared blocking pool. The actor parks during the call, and a kill is deferred until the call returns, because the call borrows the actor's data.
Consequences
- Validated by the M0 spike:
- preemption of 1000 actors,
- a panic crashes only its own actor,
- killed actors release all their memory,
- shutdown leaves 0 live blocks.
- Pinning can cause load imbalance until work stealing lands. That is acceptable for the v0 demo.
- Deep-copy send costs O(message size). Large payloads should be
Bytes, which are shared.
Alternatives considered
- Untyped
Pid<msg>mailboxes. They can't typecallreplies or DOWN messages, so they were replaced bySubjectandSelector. - Per-actor heaps with heap fragments. See ADR 0002.
- Async/await instead of fibers. That would colour every function and conflict with effect polymorphism.
Implementation note: interpreter semantics (M6, part 1)
The reference interpreter implements this model before the native runtime. It is the oracle that the native runtime must match.
The proc effect:
procis an ordinary effect declared instd/process:spawn,self,subject,send,receive(with a timeout),link,monitor,kill,trap_exits,exits,sleep.- Operations not handled inside an actor reach its root, where the scheduler answers them.
- Because it is an ordinary effect, a test can handle
procitself. It must then handle every operation (E0504), so mocking is verbose. A mock with scripted replies is not type-safe either: see the note on testing and supervision below.
Determinism:
- The run queue is round-robin, and an actor is preempted after 2000 calls.
- Spawned actors run after their parent's current slice.
- Time is virtual: when nothing can run, the clock jumps to the next timeout.
- Program output is therefore reproducible, and
tests/runrelies on it.
Exits follow Erlang:
- Actors that trap exits receive an
ExitSignalfor every linked exit, normal ones included. - Other actors die of abnormal exits only.
- Monitors get
Down. Monitoring an actor that is already gone yieldsDown(_, Crashed("noproc")). - Linking to an actor that is already gone does nothing. Erlang would send
noproc; revisit in the native runtime.
Libraries: std/actor (start/call/cast) and std/supervisor (one_for_one and one_for_all, with a restart limit) are written in Louise on top of std/process.
Not yet:
- Messages are not deep-copied: interpreter values are immutable except
Ref.
Later parts:
Selectorand rest_for_one (M6 part 3). A selector waits on several tags at once through theprocoperationreceive_any, which answers the tag with the message; the map function registered for that tag converts it.- Both backends refuse to send (or spawn with) a
Ref, a region or a handler: the sender crashes. The native runtime decides per block whether to move, share or copy (ADR 0002, Revision 1;docs/runtime-abi.md).
Revision 1 — 2026-10-09: multi-threaded from day one
Status: Accepted — 2026-10-08, with the rest of this ADR (issue #2). Decided by the project owner. This supersedes "v0 pins each actor to a thread". Sending follows ADR 0002, Revision 1: move, share or copy.
- Scheduler: M:N with work stealing. Each thread has a run queue (crossbeam-deque), and idle threads steal half of another queue.
- What made migration risky is gone: thread-locals were removed by the explicit context, and the context switch is now the runtime's own, which can be moved between threads.
- Mailboxes: lock-free and multi-producer, plus an atomic actor state (running, runnable, waiting), so a message arriving while the actor goes to sleep is never lost.
- Timers and blocking calls: a timer wheel per thread, and a separate pool for blocking FFI calls.
- Determinism for tests:
LOUISE_THREADS=1runs one thread with the interpreter's ordering, sotests/runoutput is reproducible and comparable with the interpreter. - Verification:
- loom models of the mailbox and wake-up protocol;
- ThreadSanitizer on the runtime and generated code;
- stress tests (100k actors, crash and restart storms) with the leak oracle at 0.
Implementation (M6 part 5) — 2026-10-09
Status: Accepted by the project owner on 2026-10-12; needs engineering review (#44). It realises Revision 1 in two steps, and this is the first.
- Moving fibers: corosensei fibers are wrapped in a type declared
Send, instead of the runtime's own context switch. Decided by the project owner: it lands the scheduler before #35. The safety argument (no thread-local state is held across a suspension) is written at the wrapper inlouise_rt/src/sched.rs. Since ADR 0011, fibers use the runtime's own switch on x86_64 Linux; the same argument applies. - One queue, one lock: the threads share one run queue, and the OTP state is behind one mutex, rather than per-thread deques and lock-free mailboxes. It is simple to check, and the 100k-actor stress test runs in about 1 s on 8 threads. Per-thread queues with stealing and lock-free mailboxes are the second step, when measurements ask for them. loom models come with them, since this step has no lock-free code: its races are covered by running every test program on 4 and 8 threads (exit status and leak oracle), the stress test, and the HTTP demo's end-to-end test.
spawn_linkis an operation: spawning and linking happen under one lock. As two operations, a child could stop on another thread before the link existed, and its supervisor would never hear of it.spawnfollowed bymonitorcan seenoproc, as in Erlang, when the child stops first.spawn_monitor(also an operation) spawns and monitors in one step and returns the pid with the subjectDownarrives on.- Version check: generated code passes the number of
procoperations it expects totl_root_cap, which stops with a clear message when the runtime was built for another number (a staleliblouise_rt.a). - Not yet: ThreadSanitizer (the Rust runtime would need an instrumented standard library) and per-thread timer wheels.
Implementation (M6 part 6): the Send check — 2026-10-09
Status: Accepted by the project owner on 2026-10-12; decided by the project owner among three options (a sound Send trait with where Send<m> bounds, this check, or the runtime check only); needs engineering review (#44). It refines "a static Send auto-trait" above. Revision 6 replaced it: implemented, still Proposed until engineering review.
- Static, on concrete types only (E0704,
louise_types/src/send.rs): where a body's types mentionSubject<m>withmknown,mmust not hold aRef, nor aResource<k>whose kindklacks@thread_safe. ADTs are checked through their fields, and tuples through their items. Type variables and function types are assumed sendable, so generic code needs no bounds. - At run time, the move/share/copy walk refuses what the types do not show: closures capturing a
Ref, a region, or a handler's capability. Handler capabilities now carry their own tag (CAP) for this. Before, a closure using afnhandler could be copied to another actor, where afinal ctlwould have unwound to a frame that is not on that actor's stack. The interpreter refuses the same values. - Why not a trait: sound checking needs
where Send<m>on every generic function that creates or sends on subjects (std/actor,std/process.select, user helpers), and a kind-level marker for resources anyway. The runtime check is exact, closures included, so the static check is a convenience that catches the common mistakes early.
Revision 2 — 2026-10-09: per-thread queues and per-actor locks
Status: Accepted by the project owner on 2026-10-09 (PRs #54–#59); needs engineering review (#44). This is the second step of Revision 1 (issue #43, v1 milestone #45). It replaces the shared run queue and the single scheduler lock of the first step.
Decision
- Run queues: each scheduler thread has a FIFO queue (crossbeam-deque). A thread with nothing to do takes a batch from the shared queue, then steals from the others'. The shared queue only receives actors queued from outside a scheduler thread, such as the first actor.
- With
LOUISE_THREADS=1there is one queue, so actors run in the order they were queued, as in the interpreter. - A preempted actor goes back to its own thread's queue without waking another thread: no new work appeared. Waking a sleeper there made it steal the actor to another core at every slice, so single-actor programs ran 35–40% slower on 22 threads than on 1. They now run at the same speed. Spawns and wake-ups still wake a sleeping thread.
- With
- Per-actor locks, not lock-free mailboxes: what other actors touch (the mailbox, the wait state, links and monitors) is behind the actor's own lock. Revision 1 planned lock-free mailboxes. Per-actor locks remove the global contention, and their critical sections are a few field updates. A lock-free mailbox would also need a separate wake-up protocol for selective receive. If profiling ever shows a hot actor's lock, the decision can be revisited. (It did: ADR 0028 measures fan-in, and proposes a lock-free inbox.)
- Monitors move to the watched actor. An exit no longer scans every monitor in the program.
- Timers are a heap of (deadline, pid, wait number), no longer a scan of every actor. A timer whose wait has ended (a message arrived, or the actor waits again) is dropped when it reaches the top. Equal deadlines pop in pid order, as in the interpreter.
- One control lock guards timers, sockets, blocking calls and the end of the program. It is off the hot paths of sending, receiving and scheduling.
- Lock order: the actor table, then the control lock, then one actor's lock, then the sleepers' lock.
- Two hand-offs are factored out and model-checked with loom (
louise_rt/src/handoff.rs, run in CI):RunState: a wake-up never queues a running actor, and never queues an actor twice; the thread running it queues it when it yields.Sleepers: a thread going to sleep and a thread pushing work never miss each other. ASeqCstfence on each side, between its write and its read, guarantees it. loom models fences exactly, and it found the protocol deadlocking without them.
- The idle thread waits on the reactor alone. New work, a sooner timer, the end of the program and finished blocking calls all signal its waker.
- Per-thread timer wheels and ThreadSanitizer are not done. The timer heap is a single structure that the idle thread reads. ThreadSanitizer still needs an instrumented standard library.
Measurements
Release builds, best of 3, interleaved with the first step's runtime on the same machine:
| Program | Threads | Shared queue, one lock | This revision |
|---|---|---|---|
tests/bench/messages.lse (a 1,000-actor ring) | 1 | 222 ms | 167 ms |
| 8 | 1,333 ms | 679 ms | |
| 22 | 1,793 ms | 781 ms | |
tests/stress/actors.lse (100k actors) | 1 | 4,063 ms | 3,309 ms |
| 8 | 837 ms | 786 ms | |
| 22 | 1,605 ms | 737 ms |
The ring is sequential: each hop wakes the next actor, so more threads only add cross-thread hand-offs. It is still fastest on one thread.
Verification
- Every native test program, 20 times each on 8 threads: same exit status as one thread, with the leak oracle at 0.
- The stress test on 1, 2 and 8 threads, and the HTTP demo's end-to-end test with 22 threads.
- The loom models, including a check that each one fails when its fence is removed.
Revision 3 — 2026-10-09: real time once a socket opens
Status: Accepted by the project owner on 2026-10-12; needs engineering review (#44).
Context
Before this revision, the clock followed real time only while one thread was idle and waiting on the reactor. It froze while every thread had work. Under load, an HTTP connection's idle timeout (ADR 0012) therefore never expired, and neither did any other receive timeout or sleep. A test reproduces this: one actor spins while a connection stays idle, and the connection was never closed.
Decision
- Once the program opens its first socket, the clock follows real time for good.
- Programs without sockets keep the virtual clock and stay reproducible.
tests/runrelies on that, and the interpreter has no sockets. - A program that talks to the network cannot be replayed anyway. Its timeouts must expire while other actors keep every thread busy.
- Programs without sockets keep the virtual clock and stay reproducible.
- The clock is counted between slices. A scheduler thread finishing a slice adds the whole milliseconds elapsed since the last count, and wakes the actors whose deadline has passed. It skips this when another thread holds the control lock. The idle thread does the same after each wait.
- Idling in real time waits for the deadline. When nothing runs and no socket or blocking call is pending, the idle thread waits on the reactor until the next deadline instead of jumping to it. With no deadline at all, it is still a deadlock.
- The switch is one-way. Going back to virtual time when the last socket closes would make the clock jump ahead of real time.
Consequences
- Deadlines can be slightly early. A deadline is computed from the clock as last counted, which can lag by the slice running at that moment. A timeout can therefore expire early by up to one slice.
- Timeouts after a socket are real. In a socket program,
sleepandreceivetimeouts now take real time even when nothing else is happening. Previously the clock skipped ahead in that case. - Cost: each thread now takes the control lock once per slice, but only with
try_lock, and only in socket programs. Such programs already did this whenever a socket was waited on.
Verification
crates/louise/tests/cli.rshttp_idle_timeout_under_loadruns a spinning actor with an idle connection on 1 and 4 threads. The test failed before this change: the connection was never closed. It now closes after about 200 ms.
Revision 4 — 2026-10-09: fewer wake-ups, cheaper lookups
Status: Accepted by the project owner on 2026-10-12; needs engineering review (#44). Issue #61 (profiling tests/bench with the CPU's counters). It refines Revision 2.
Context
After Revision 2, the 1,000-actor ring still ran 7 times slower on 22 threads (411 ms) than on one (61 ms). Most of the time went to a contended mutex: each message woke a sleeping thread (a futex call through the Sleepers lock), which then raced to steal the receiver from the thread about to run it. On one thread, a third of the ring's cycles went to looking actors up in the actor table: a read lock and an Arc count, all atomic, twice per receive, and SipHash on the pid.
Decision
- The first actor made ready in a slice wakes no thread. When an actor running on a scheduler thread queues another one on that thread (it sends to an actor waiting for the message, or spawns one), the first such push of the slice wakes nobody: the thread runs it after the slice. When the slice ends, the thread wakes a sleeper only if more than one actor is queued on it. Later pushes in the same slice wake a sleeper as before, so an actor spawning many workers still spreads them at once. This is the "LIFO slot" of other work-stealing schedulers (Tokio, Go), without the slot: the actor stays in the stealable queue.
- A thread that finds work while more is queued wakes the next sleeper, so wake-ups spread from thread to thread while work remains.
- Lost wake-ups: none are introduced. Work queued without a wake-up is in the queue of a thread that is running and looks at its queue as soon as the slice ends; slices are bounded by preemption. The
Sleepershand-off and its loom model are unchanged; it is just called less often. - A running actor reaches its own state without the actor table, through the cell pointer it already keeps (the table keeps the cell alive while the actor's fiber lives).
- Pids and subject tags are hashed with one multiplication (FxHash's), not SipHash. They are the runtime's counters, never program input, so resistance to collision attacks buys nothing.
- Links are a set that keeps its insertion order (the order exits propagate in), so an exit removes itself from a linked actor in constant time. A vector made
tests/stress/actors.lse(main linked to 100,000 children) quadratic.
Measurements
Wall time, best of 7, on a shared 22-thread laptop:
| Program | 1 thread | 2 | 4 | 8 | 22 |
|---|---|---|---|---|---|
messages, before | 61 ms | 138 | 215 | 300 | 411 |
messages, after | 64 ms | 58 | 60 | 59 | 63 |
parallel (64 actors computing), before | 1183 ms | 541 | 287 | 159 | 113 |
parallel, after | 1012 ms | 532 | 278 | 164 | 104 |
tests/stress/actors.lse, before | 2248–2843 ms | 671–759 | 316–345 | 393–408 | 405 |
tests/stress/actors.lse, after | 952–1053 ms | 434–495 | 372–425 | 438–485 | 461–500 |
On one thread, messages runs 22% fewer cycles (36% fewer instructions) from the lookups alone. The stress test is more than twice as fast on one thread (links). On 4 to 22 threads it is 10–20% slower, and about as slow with the links change alone: hashing each of 100,000 links costs more than pushing it to a vector. This is near this machine's noise, and to be watched.
Consequences
- A message's receiver may wait for the sender's slice to end (at most 2,000 reductions) while other threads sleep, where it would have been stolen before. That is the trade: latency within a slice for no system call per message.
- Verification: the native tests on 1 and 4 threads, the stress test, the HTTP tests (keep-alive, the idle timeout under load) and the loom models.
Note — 2026-10-12: one link inline (issue #104)
Status: for review with this revision (#44).
The cost on 4–22 threads was allocations, not hashing. Each child linked to main made four Rust allocations: its boxed ties, the set's table, the order vector, and the vector of links at exit. These were allocated on the spawning thread and freed on whichever thread the child exited on.
The fix: Links keeps one link inline (Links::One), which is the usual case, a child linked to its parent, and becomes the set at the second link. A linked child now allocates its ties and its exit vector only.
tests/stress/actors.lse, best of 9, before and after interleaved, ms:
| Threads | 1 | 2 | 4 | 8 | 12 | 22 |
|---|---|---|---|---|---|---|
| before | 891 | 370 | 348 | 387 | 400 | 414 |
| after | 882 | 319 | 297 | 344 | 355 | 382 |
| change | −1% | −13% | −14% | −11% | −11% | −7% |
On 4 threads that is faster than before links were a set (316–345 ms), with the set's constant-time removal kept for actors with many links.
parallel and messages never link, so they are untouched in principle.
parallel's instruction counts are the same.messagesran 1.3% more instructions. That was the runtime's codegen-unit split moving inlining decisions in the receive path, not the links. With one codegen unit,messagesruns the same instructions before and after (298,754,197 against 298,753,201). One codegen unit is also 9% fewer instructions onmessagesoverall (issue #126).
Revision 5 — 2026-10-09: timers off the control lock, and ThreadSanitizer
Status: Accepted by the project owner on 2026-10-12; needs engineering review (#44). It completes Revision 2's "not done" items for issue #45: per-thread timers and ThreadSanitizer.
Context
Revision 2 left timers in one heap under the control lock. Each receive with a timeout and each sleep pushed a timer there, and in real time (Revision 3) every thread took the lock again between slices, to count the clock and fire due timers.
Before changing anything, a timer-heavy benchmark measured it (tests/bench/timers.lse, added for this). It has 1,000 client/server pairs calling each other with timeouts that never expire, plus 2,000 actors that sleep or time out 50 times each. A temporary probe counted the control lock's contended acquisitions:
| Workload (1,000 pairs × 1,000 calls) | Threads | Contended | Time spent waiting, all threads |
|---|---|---|---|
| virtual time | 8 | 43% of 2.0 M | 1.4 s (run: 1.0 s) |
| 22 | 54% | 7.4 s (run: 1.4 s) | |
| real time (a socket open) | 8 | 72% | 6.2 s (run: 1.5 s) |
| 22 | 69% | 27.9 s (run: 1.8 s) |
Against the same program waiting forever (no timers), the timeouts cost 7–10% in virtual time on 8–22 threads, and 28–44% in real time. Real time is the case that matters: it is how every socket program runs, the HTTP demo included.
Decision
- A heap per scheduler thread (
louise_rt/src/timers.rs). An actor adds its timer to the heap of the thread running it, behind that heap's own lock. Another thread takes that lock only to fire timers. - A lock-free lower bound on the earliest deadline. Between slices, a thread checks whether any timer may be due with one atomic load. Only then does it try to fire.
- One thread fires at a time (a
Firingguard, taken withtry_lockbetween slices). It takes the due timers out of every heap and sorts them by (deadline, pid), so the order is the single heap's:- due actors still wake in pid order for equal deadlines;
- with
LOUISE_THREADS=1there is one heap, and outputs still match the interpreter.
- The bound stays a lower bound because it changes only under heap locks. An adder lowers it while holding its heap's lock; the firing thread recomputes and stores it while holding every heap's lock.
- This is checked with loom (
timers::loom_models, run in CI with the hand-off models). The models fail when an adder lowers the bound after releasing its heap's lock. - A first version reset the bound before scanning the heaps, without holding them all, and argued correctness from the C++ memory model. loom reported a lost timer. loom models an atomic's modification order only partially, so the report may be loom's limit rather than a real bug; but the version that holds the locks needs no such argument.
- This is checked with loom (
- The real-time clock is a start instant, set once (
OnceLock, under the control lock so that it cannot race a virtual jump). Any thread counts it without a lock, and writes the shared clock only when it has moved. - Unchanged: virtual jumps happen in the idle thread, under the control lock (now with the
Firingguard too); timers whose wait ended are dropped when met; deadlines are still computed from the clock as last counted (Revision 3). - Two consequences of taking timers off the lock, both fixed in the same change:
- Actors woken by timers are all queued, then sleeping threads are woken once. Waking one sleeper per actor made 2,000 simultaneous sleepers 2–6× slower on 8–22 threads: the control lock used to keep the other threads off while the idle thread fired. This fits Revision 4's wake-ups: timers fire outside any slice (between slices, or in the idle thread), so Revision 4's first-push deferral does not apply there; and each woken thread that finds more work queued wakes the next, which spreads a large batch.
- A new timer nudges the idle thread only in real time. In virtual time, the idle thread never waits for the clock, and the nudge cost a system call per timer.
- Why not timer wheels (Revision 1's plan): a wheel makes insertion and cancellation O(1). Here, cancellation is already free (a timer is dropped lazily, by its wait number), and per-thread heaps remove the contention. Wheels would also need levels for virtual time, which can jump arbitrarily far, and a sort for the pid order. They can be revisited if heap pushes ever show in a profile.
Measurements
Measured on top of Revision 4 (v1-speed-runtime), against it, on a quiet machine. Release builds, best of 7 runs, the two builds interleaved; *_rt variants open a socket first, so they run in real time; pairs_big is the benchmark's 1,000 pairs alone, with 1,000 calls each; sleepers is its 2,000 sleeping or timing-out actors alone.
| Program | 1 thread | 8 threads | 22 threads |
|---|---|---|---|
tests/bench/timers.lse (virtual time) | 145 → 133 ms (−8%) | 135 → 124 ms (−8%) | 167 → 147 ms (−11%) |
pairs_big | 649 → 635 ms (−2%) | 687 → 611 ms (−11%) | 868 → 685 ms (−21%) |
sleepers | 51 → 53 ms (+3%) | 67 → 59 ms (−11%) | 76 → 65 ms (−14%) |
timers_rt | 170 → 155 ms (−8%) | 197 → 162 ms (−17%) | 245 → 202 ms (−17%) |
pairs_big_rt | 899 → 697 ms (−22%) | 1,206 → 581 ms (−51%) | 1,442 → 720 ms (−50%) |
sleepers_rt | 114 → 111 ms (−2%) | 101 → 113 ms (+11%) | 116 → 113 ms (−2%) |
- The rest of
tests/bench(scripts/bench.sh --compare, 7 runs, on 1, 8 and 22 threads) is within noise:arith,arrays,dict,effects,floats,html,lists,messagesandparallelmove between −12% and +4%, with no direction across thread counts. - Socket programs gain most: a timeout no longer takes a contended lock, and neither does the per-slice clock.
sleepers_rtis dominated by its real 1 ms sleeps; its +11% on 8 threads is within that noise. - A regression found and fixed while measuring: storing TSan's call depth (a constant outside TSan) on every fiber suspension made
effects25–38% slower; it is now compiled only in TSan builds (ADR 0011 note). - Before Revision 4, measured against
main, the virtual-time timer benchmark was 2–5% slower on 8 and 22 threads. On top of Revision 4 it is faster at every thread count.
ThreadSanitizer
scripts/tsan.shruns ThreadSanitizer on the runtime's unit tests, then on native programs: everytests/runprogram on 4 threads (but one, see below), and the stress test, the message ring and the timer benchmark on 8. It fails on any report, a wrong exit status or a leak. CI runs it withLOUISE_CI_TSAN=1; it is opt-in because it needs a nightly toolchain withrust-src. It takes about a minute, plus a few minutes the first time, to build the instrumented standard library.- What it needs:
- the runtime and Rust's standard library instrumented: nightly
-Zsanitizer=thread -Zbuild-std; - the runtime built without mimalloc, whose C code is not instrumented;
- fiber switches announced to TSan (
--cfg louise_rt_tsan, ADR 0011 note); - generated C built with
-fsanitize=threadbut without TSan's function entry/exit hooks (-mllvm -tsan-instrument-func-entry-exit=0). The hooks do not pair up acrossmusttailcalls, so an endless tail-recursive loop (tests/run/process.lse'sspin) overflowed TSan's shadow call stack. Memory accesses are still checked; reports show fewer C frames.
- the runtime and Rust's standard library instrumented: nightly
- A limit: TSan's shadow call stack holds 64Ki frames per fiber, without a bounds check. Recursion deeper than that through instrumented runtime frames silently corrupts TSan's own memory. It showed as CHECK failures in TSan's allocator, thousands of bogus use-after-free reports, or a hang, at random, in
tests/run/generators.lse: there,x + resume(())nests 20,000 handler resumptions, about 80,000 runtime frames. The script skips that program, with the reason; ASan and the differential tests still run it. Turning off the hooks for the runtime too would remove the limit, but reports would lose their stack traces. - Findings: no race in the runtime or in generated code. One report is suppressed (
scripts/tsan.supp, with its reason): crossbeam-deque's stealer reads a slot speculatively and discards the value when its compare-and-swap fails, which is the deque's design. - Checked: a deliberate data race in a runtime unit test is reported, so a clean run means something.
- Cost under TSan: programs run about 25–40× slower than release builds (the runtime is a debug build there). The 100k-actor stress test takes about 10 s on 8 threads.
Verification
scripts/ci.sh(TSan off), andscripts/tsan.sh.- The loom models: the existing hand-offs, plus
timers::loom_models(an add racing a firing thread; two adds racing a scan). - Every
tests/runprogram, 20 times each on 8 threads: the same exit status as one thread, with the leak oracle at 0. scripts/stress.shon 8 threads and on 1.
Note — 2026-10-12: supervision uses links, and how to test actors (issue #159)
Status: for review (#44).
Why supervision uses links, not handlers. A common idea is to make a supervisor an effect handler wrapped around its children, catching their crashes. In Louise it can't work:
- A child runs on a fiber of its own, maybe on another thread, so a handler on the parent's stack never sees the child's code.
- Panics are not effects (ADR 0001, "let it crash"), so no handler catches one.
So crashes travel as exit signals over links, and std/supervisor traps them (trap_exits, spawn_link). spawn_link is one operation, so that a child can't stop before its link exists (above). A mock that does spawn then link would bring that race back.
Mocking proc is not practical. A handler of proc must cover its 14 operations (E0504). Worse, scripted replies are not type-safe:
- the subjects are created inside the code under test, so a test can't name their message types;
- a reply of the wrong type would be read as another type. Issue #169 found that handler clauses aren't checked against an operation's polymorphism.
What to do instead:
- Real actors as fakes: a spawned stand-in that answers from a script.
- Subjects as parameters: the code under test takes its collaborators' subjects as parameters.
- Virtual time: it makes timeouts deterministic (Revision 3: virtual until a socket opens).
The demo's store tests call the store's message handler directly, which needs no actor at all.
Note — 2026-10-12: a sharded actor table, and the stack pool off the control lock (issue #131)
Status: Proposed (epic #135); needs engineering review (#44).
What changed:
- Own-pid lookups skip the table. Eight places where the running actor looked itself up by pid now use its own cell (
Actor::with_proc), asreceivealready did (Revision 4):link,trap_exits,exits,sleep, a blocking call, console back-pressure, a socket wait, and the end of an actor. - The stack pool has its own lock. Before, it was in
control, and themadvisefor a cold stack ran while holding it. The system call now runs outside any lock, and the pool's bounds are loose by a few stacks. - The table is split in 64 shards by pid (
Table), each aRwLock, with the number of actors in an atomic beside them. Listing every actor (whenmainends, on a deadlock) sorts by pid, so the order stays the spawn order. --features lock-statsnow counts each lock separately: actors,control, the table's reads and writes, and the stack pool.- A benchmark:
tests/bench/churn.lse, 64 actors each spawning 2,000 short-lived children.
Why sharding: #131 proposed a lock-free table (a slab with generations, or epoch-protected entries). The plan was to do it only if contention showed. On 22 threads, churn found the single lock taken for 58% of its reads and 86% of its writes. Sharded, that's 0.1%. A lock-free table would still save the uncontended read lock and Arc count on one thread; that's left for when it shows in a profile.
Measured against the stack's previous PR (#172), release builds:
22 threads, wall time, median of 15–25 runs:
Benchmark Change churn−60% (533 → 211 ms) timers−32% (215 → 145 ms) messages+3% fanin+2% selective+1% One thread, user cycles, best of 9–15:
idle−13%,churn+1.6%,messages+3.8% (+1.0% instructions: the shard's index);arrays+5.2% anddict+4.7%, with the same instructions. Neither touches the table: their hot functions (mi_freeand the program'stl_entry, which ThinLTO inlines runtime code into) moved alignment. Againstmainthey stay 23% and 13% faster.- Every other benchmark is within ±3%.
Lock order, corrected. Revision 2 put the actor table first. The order the code keeps is the one documented on Shared:
control;- the right to fire timers;
- one timer heap;
- one actor's lock;
- the sleepers' lock.
The table's shards and the stack pool are each held for one operation, never while taking another lock, so they may be taken under any of these.
Not done: the run queue still holds pids, not cell pointers. Each run of an actor looks it up in the table; a pointer would save that lookup, at the cost of a reference count per queued entry.
Note — 2026-10-15: several actors on one socket, and no lost readiness (issue #221)
Status: Proposed; needs engineering review (#44).
The problem: the reactor kept one waiting actor per socket (io_waiters: token → pid) and a ready flag per socket (io_ready), and both lose wake-ups:
- A second waiter replaced the first. A socket is a
Resourceany actor holding it may use: one actor reading while another writes, say. The second to park overwrote the first, which was never woken. Andio_unwait, removing by socket only, could remove another actor's wait. - Readiness reached only one actor. An event woke the waiter if there was one, and set the flag only if there was none; the next
io_waitcleared it. An actor between itsWouldBlockand itsio_waitwhen the event came — or a second actor arriving after the first consumed the flag — parked and was never woken: sockets are registered edge-triggered, so that event never comes again.
The decision:
- Every waiter is kept, and every one is woken.
io_waitersholds the pids waiting on each socket; an event wakes them all, andio_unwaitremoves only its caller's. A socket has one token for both directions, so a reader may be woken by writability: it retries, findsWouldBlock, and parks again — the cost of a spurious wake-up, never a lost one. - Readiness is a count, not a flag. The reactor counts the socket events it delivers, all sockets together, under the control lock and whether or not someone waits. An actor reads the count before its attempt (the read, write, accept or connect that may find
WouldBlock) and passes it toio_wait, which, under the same lock, refuses to park if it moved: an event came since the attempt, so it retries. One count for the whole reactor rather than one per socket: reading it is one atomic load and no lock on every attempt, and nothing has to be kept per socket or removed when it closes; the price is a retry when another socket's event happens to come in that window. io_waiting, which the idle and deadlock checks read, counts waiting actors, not sockets.
Verification: a fixture with one actor reading and another writing the same socket (crates/louise/tests/cli.rs), on 1 and 4 threads, with the leak oracle; ThreadSanitizer (scripts/tsan.sh).
Revision 6 — 2026-10-15: Send as an auto trait, and captures in function types (issue #233)
Status: Proposed; needs engineering review (#44). It replaces "Implementation (M6 part 6): the Send check" above. That section recorded the project owner's choice of a check on concrete types over "a sound Send trait with where Send<m> bounds"; this revision takes the second option and goes further, to closures.
Context
The check of M6 part 6 looks only where a body's types mention Subject<m> with m known. Three kinds of values slip past it, and the runtime's move/share/copy walk (ADR 0002, Revision 1) refuses them only when one is sent, by crashing the sender:
- Generic code.
fn relay(s: Subject<m>, x: m) { process.send(s, x) }is never checked, and neither is a callrelay(s, a_ref)elsewhere. - Hidden types. An existential constructor (ADR 0041) hides the type of what it holds.
- Closures. A function type does not say what the closure captured: a
Ref, a non-thread-safeResource, or the capability of a handler on this actor's stack (ADR 0010).
Associated types (ADR 0047) would add a fourth: a field of type Elem<c> in a message type.
Decision
Send<a> is a built-in auto trait.
The prelude declares
pub trait Send<a> {}. It has no methods, and no impl may be written for it (an error at the impl).It holds structurally:
Type SendwhenInt,Float,String,Bytes,bytes.Builder,Pid,Subject<m>,Dynamicalways. These are values or handles; BuilderandArraycopy on write.Ref<h, a>never: it belongs to its region, in one actor. Resource<k>when the kind type kis marked@thread_safe.Array<a>, a tuplewhen their elements are. an ADT when every field of every constructor is, with the type's arguments substituted and projections reduced. Recursive types are checked coinductively: Send<List<a>>assumes itself while checkingCons.an existential constructor only if it stores Sendfor the types it hides (where Send<s>on the constructor).a type variable, or a projection that does not reduce only if a given says so: a where Send<a>, or one inferred into an unannotated function's scheme.a function type when its capture row is empty (below). Its evidence is erased. A
Sendconstraint is solved like any other, but it has no dictionary: no parameter, no argument, nothing in Core. The generated code is the same with or without it.Where it is required: wherever a value crosses to another actor.
process.sendrequiresSend<m>. Subjects themselves are alwaysSend, so creating and receiving need nothing.actor.startrequiresSend<s>of its initial state.- The functions that run in another actor are
send fn(below):spawn's,spawn_link's andspawn_monitor's body,actor.start's handler, andsupervisor.Child's start function. - Effect operations may therefore carry
whereclauses.
Errors keep code E0704, with a chain saying why: "
Jobhas a fieldcache: Ref<h, Dict<String, Int>>, which belongs to its region". A missing given in an annotated generic function is E0402: "addwhere Send<m>".
Function types record their captures.
A function type has a capture row, separate from its effect row, with a single label,
Local. A function whose capture row is closed and empty captured nothing that cannot be sent.Written types:
send fn(a) -> b / <e>is a function that can be sent.sendis contextual: a keyword only in a type, beforefn; it stays a valid name everywhere else, asprocess.sendneeds.- A plain
fn(a) -> bin a signature has a fresh capture row, generalized with the signature. It accepts any function, and its body cannot send it. - A plain
fnin a type definition's field isLocal: a value of that type is notSend. A message type that carries a callback sayssend fn.
Closure literals start with an open capture row. When their function's inference ends, for each captured variable of type
t:- if the row was closed by a
Sendrequirement,Send<t>is required: the closure is sent, so what it holds must be sendable; - otherwise, if
Send<t>does not hold, the row getsLocal.
A closure whose row stays open has therefore had its captures checked, so generalizing that row is sound: a caller that later sends the closure needs nothing more. Without that order,
fn make(r) { fn(x) { x + ref.get(r) } }could return a closure generalized over its captures and be sent by a caller.- if the row was closed by a
Always
Local: a closure that uses a handler's capability from where it was written (a label of its row whose instance is notBound, ADR 0010), andresume. Both live on this actor's stack. Capabilities a declared arrow type passes in (Bound) are not captures: a spawned body receives the new actor's own rootproc,clock,random,ioandffi.Top-level functions used as values capture nothing.
Send<fn …>closes the capture row. A clash withLocalis E0704, naming the capture: "this closure capturesr: Ref<h, Int>, which belongs to its region".Printing: a type prints
send fnwhen its row is closed and empty, andfnotherwise. Signatures inserted by the language server therefore stay valid.
Refined while implementing it (2026-10-15, same status):
- Only a parameter's own type is generalized. A plain
fnthat is a parameter's whole type gets a capture row the caller chooses. Every other plainfn(a result, a field, an alias, or a function type nested inside another type, including a parameter'sList<fn…>orfn(fn…)) isLocal. Generalizing a nested one would be unsound: a body could hand the caller aLocalclosure through a position the caller had chosen to be sendable (aRef<h, fn…>, or a callback's argument). - An expected
Localaccepts any function. Where an expression is checked against a type (an argument, a field, a result), a function type whose row isLocaltakes any function without unifying rows: it is never sent, so what was captured does not matter. Values read back out of it areLocal. This replaces the "no subtyping" mismatch for the common cases; it remains for functions inside other values (Some(f)whereOption<fn…>is expected). - A named function used as a value captures nothing, unless it captures a capability (ADR 0010): then it is
Local. - A closure whose captures are verified keeps an open row, decided innermost first, so an outer closure that captures it is not made
Localbecause the inner row is still open. - A type variable nothing determines is
Send: only polymorphic values have such a type, or what@externcode produces — which the runtime walk still checks. - A type a constructor hides is an obstacle only if a field stores a value of it:
Ask(Request<r>, Subject<r>) -> Msgis sendable, since a subject is a pid and a tag.
The runtime check stays. The move/share/copy walk still refuses pinned blocks and captured capabilities. It no longer catches anything a well-typed program can do, but it costs nothing on the common path and guards @extern code and future gaps.
Consequences
- Annotated generic actor code needs
where Send<m>. Instd, that meansactor,supervisor,http's connection actors, and user helpers likerelay. Unannotated functions infer it. - Callbacks that cross actors are
send fn: the spawn family,actor.start,supervisor.Child, andstd/http's handler, which runs in each connection's actor. Code that passes a closure capturing aRefor a local handler there no longer compiles. Before, it crashed when sent. - No subtyping: a closure value that is both sent and stored in a field typed plain
fnis a type mismatch, because the field saysLocaland the send says empty. The error suggestssend fnfor the field. This is the price of keeping HM inference without subtyping. - Checking cost: one structural walk per distinct
Sendconstraint, cached per type definition, assend.rsdid. The generated code is unchanged: the evidence is erased, and capture rows are types only. send.rsis removed; its error code is kept.
Alternatives considered
- Keep the check on concrete types (M6 part 6). It is simpler, but unsound for generic code, existentials and closures, and it would also miss projections.
Sendwithout capture tracking: function types assumed sendable, as before. It leaves the commonest runtime crash, a spawned closure capturing aRef, to run time.- Function types never
Send. Sound and simple, but it would refuse everyspawn. - Effekt-style capture sets (rejected for effects by ADR 0010). They track which values are captured;
Sendonly needs to know whether any of them cannot be sent, which a one-label row says with ordinary row unification. - Each closure its own nominal type, as in Rust. That needs subtyping or traits for every higher-order parameter.
- Subtyping between
send fnandfn. It would remove the mismatch above, but HM inference with subtyping loses principal types.
Revision 7 — 2026-10-23: Shutdown and process.stop (issue #306)
Status: Proposed; needs engineering review (#44). The design and its reasons are ADR 0060's; this records what changes in the actor model.
ExitReasongainsShutdown(constructor 3): an actor asked to stop, not crashed. It is abnormal for links, likeKilled(a linked actor that does not trap exits stops too, withShutdown), and is never reported as a crash.process.stop(pid), the fifteenthprocoperation: a target that traps exits getsExitSignal(self(), Shutdown)and decides when to return; any other stops withShutdownat its next safe point, as withkill.killis unchanged.- A root that stops with
Shutdownends the program with status 0. - Signals (
std/os.signals) arrive as messages from the runtime, likeDown: the signal thread never runs actor code (ADR 0060, Signals).
Note — 2026-11-01: demonitor, the sixteenth proc operation (#414), and an opaque Selector
process.demonitor(pid, down)is the sixteenthprocoperation: it stops the monitor thatmonitor pid(orspawn_monitor) made, whoseDownsubject isdown. NoDownarrives on it afterwards; one that already arrived stays, anddemonitor_flushdrops it too.downmust be the caller's (another actor's panics); any other pid, or a subject that is no monitor's, is ignored. EachDownis delivered under the lock that ends its monitor, so ademonitornever races one that is on its way. Across nodes it is tie op16(docs/wire-format.md, ADR 0072).- A Louise handler of
procneeds ademonitorclause: it must cover all 16 operations (E0504), and generated code passes 16 totl_root_cap's version check. A test double ofprocwritten before #414 no longer compiles until it has one. Selectoris opaque (dist/hardening2, #404's second security review). An entry pairs a subject's tag with the map that reads its messages as that subject's type, and onlyselectingmay pair them. As a public record, a program could rebuild an entry with another subject's tag and read anIntas aString(SIGSEGV), with std alone. Building, matching or reading aSelectoroutsidestd/processis E0117.
Note — 2026-11-02: unlink, the seventeenth proc operation (#422)
process.unlink(pid)is the seventeenthprocoperation, with Erlang's guarantee: once it returns, the link has no effect on the caller until a newlink, and the caller's exit none onpid. AnExitSignalalready in the mailbox stays. Unlinking a pid with no link, a dead pid, or itself does nothing.- An exit through a link counts only through a half its receiver still has, local exits included (until #422, a local one always counted).
unlinkremoves the caller's half, then the other's, each under its actor's lock; an exit on its way then finds no half and is dropped. Its effect, the receiver'sExitSignalor its own exit, happens under the lock that removes the half, so it never comes afterunlinkreturns, as aDownnever comes afterdemonitor. - So a link makes the linking actor's half first, then the other's, only while the other is alive and the linking actor has not exited (its kill flag, read under the other's lock): an exit then always finds the other's half when it took its own.
spawn_linkmakes the parent's half before the child is in the actor table, and stops a child whose parent exited meanwhile, as before. - Across nodes it is Erlang's protocol, tie ops
17and18(docs/wire-format.md, ADR 0072): the caller's half waits, unlinking, for the other node's acknowledgement. - A Louise handler of
procneeds anunlinkclause: it must cover all 17 operations (E0504), and generated code passes 17 totl_root_cap's version check.
Revision 8 — 2026-11-01: actors stay on their thread; one thread woken at a time (issue #418)
Status: Proposed; needs engineering review (#44): the memory model of the per-thread parkers and inbound queues, the searching protocol, and fairness of the next slot. It refines Revisions 2 and 4 (where a woken actor is queued, how sleeping threads are woken) and leaves the rest of the scheduler as it is.
Context
Profiling a web application (toki2: 100 HTTP readers, 22 threads) put about 12% of the CPU in mimalloc taking back blocks freed by a thread other than the one that allocated them (mi_page_thread_collect_to_local 7.9%, mi_free 5.9%). With LOUISE_THREADS=1 that cost disappeared. A probe runtime counted why: 62.6% of slices ran on another thread than the actor's previous slice, and 43% were steals. Three things moved actors:
- a socket, timer or blocking-call wake-up queued the actor on whichever thread polled or fired (
wake_io,fire), not where it ran; - every queued actor was stealable, so the "first push wakes nobody" of Revision 4 still left the receiver in a queue another thread could take it from;
- sleeping threads shared one mutex and condition variable (
Sleepers), and a push or a busy thread woke them freely (notify_oneper push,notify_allin several places): woken threads found the work and stole it.
An actor's memory is allocated by the thread running it, so every move made its frees remote. Messages and shared values crossing threads were negligible (0.4% of remote frees came from actors that never moved).
Other runtimes converge on the same answers. Tokio (2019 scheduler; the 2023 starvation fix, tokio#5686 and #5712) and Go (proc.go: runnext, wakep, findRunnable) keep the task woken by the running one in a per-worker slot the thief cannot take (Go makes thieves wait about 3 µs before taking it), wake a parked worker only when none is searching, let at most half the busy workers search, hand the search on when a searcher finds work, and steal half a queue from a random victim. BEAM and Pony keep processes on their scheduler and move work by stealing when idle; Pony reschedules an actor on its sender's thread.
Decision
- A message's receiver runs on the sender's thread, next. Each thread has a next slot (
Local::next) that thieves cannot see. A receiver woken by a message (or a new actor, on its spawner's thread) goes in the next slot of the thread running the sender; an actor already there moves to the back of the queue. The thread runs the slot when the slice ends, waking nobody: Revision 4's deferral, now without the actor being stealable meanwhile. The slot runs at most 3 times in a row (Tokio's cap): two actors waking each other cannot starve the queue. - Sockets, timers and blocking calls wake an actor on its home. An actor's home is the thread it last ran on (
Cell::home, written by that thread at each slice, read relaxed by wakers: a stale read only queues it on the thread before). These wake-ups go in the home's inbound queue (oneInjectorper thread), and wake that thread alone through its parker; if it is the thread waiting on the reactor, through the reactor's waker. Timers firing and reactor polls queue every actor first and wake each home once (Wakes), as Revision 5 required. - Waking a message's receiver on its home instead was measured and dropped:
timers(1,000 client/server pairs) ran 7–14% slower on 4 and 8 threads, every call crossing threads, and toki2 used 9–14% more CPU per request than with the sender's thread. - Each thread parks on its own parker (
park::Parker: a token, a mutex and a condition variable, likestd::thread's park and unpark), so work for one thread wakes that thread alone.Sleepersis gone. - Searching for work is bounded and handed on (
park::Idle):- a thread with nothing of its own may search other threads' queues while fewer than half the threads awake are searching;
- a push that leaves work to spare (below) wakes a parked thread only if none is searching, and counts it as searching at once, so a burst of pushes wakes one thread;
- a searcher that finds work stops searching and, if it was the last and work remains, wakes the next.
- Stealing takes only spare work. A searcher starts at a random thread and takes half (crossbeam's
steal_batch_and_pop) of its queue, which holds only what that thread had no time for (displaced from its next slot, spawned or preempted while it ran); from its inbound queue only past the first actor, which the thread was just woken for. Work is spare, and a push wakes a searcher (if none is searching), when it lands in a thread's queue during a slice or behind another actor, in an inbound queue behind another actor, or in the shared queue. Gating the queue too (taking only from a thread with two actors queued, as a prototype did) serialised two actors spawned together: the second sat behind the first's slice while every other thread slept (sched::tests::actors_spawned_together_run_in_parallel). - No lost wake-up. A thread lists itself as parked, stops searching, issues a
SeqCstfence, then looks for work once more; a pusher publishes its work, issues a fence, then reads the number of searchers. One of them sees the other's write. A wake-up for one thread sets its parker's token, which a later park consumes without sleeping. Checked with loom (park::loom_models: an unpark against a park,notify_oneagainst a searcher parking, a push to a thread's inbound queue against that thread parking). - Unchanged: a preempted actor goes back to its own thread's queue without a wake-up (Revision 2); the reduction budget;
RunState, the inbox and the timer heaps; one thread waits on the reactor when nothing runs. WithLOUISE_THREADS=1the next slot is not used, and the order is the interpreter's. --features sched-statscounts slices, slices on another thread than the actor's last, slices from a next slot, steals, wake-ups queued on another thread, and parks, printed at exit withLOUISE_LEAKS.
Measurements
toki2 read_heavy (10,000 notes, 100 looping readers for a minute, prod on PostgreSQL): release builds of the same toki2 with Louise 0.9.0 and with this revision, runs interleaved on a shared 22-thread laptop. CPU per request is the server's CPU time over the read phase divided by the requests it served; throughput moved with outside load, CPU per request much less.
| Run | CPU per request | read p95 | read p99 | load average at start |
|---|---|---|---|---|
| 0.9.0 (3 runs) | 1.06–1.22 ms | 10.6–11.5 ms | 118–130 ms | 2.4–16.0 |
| this revision (3 runs) | 0.86–1.05 ms | 6.3–8.9 ms | 50–67 ms | 5.1–17.6 |
| receiver woken on its home (dropped; an earlier build, against 0.9.0 at 1.17–1.18 ms; 2 runs) | 1.00–1.05 ms | 7.5–8.2 ms | 43–56 ms | 17.6–19.4 |
CPU per request fell 14–19% in each interleaved pair, p95 by 23–40%, and p99 by 45–60%; the 0.9.0 runs mostly had the quieter machine.
tests/bench, median of 7 interleaved runs (0.9.0 → this revision, ms; the machine was shared, load average 5–7). Within ±5% unless noted:
| Program | 1 thread | 4 | 8 | 22 |
|---|---|---|---|---|
messages (ring) | 48 → 46 | 49 → 47 | 49 → 49 | 51 → 49 |
fanin | 80 → 80 | 127 → 129 | 131 → 126 | 158 → 154 |
parallel | 908 → 882 | 243 → 241 | 134 → 135 | 94 → 88 |
churn | 109 → 106 | 76 → 74 | 83 → 84 | 116 → 117 |
timers | 127 → 129 | 73 → 70 | 72 → 70 | 85 → 86 |
idle | 667 → 683 | 865 → 845 | 953 → 939 | 1261 → 1203 |
selective | 36 → 38 | 41 → 41 | 47 → 53 | 44 → 52 |
ssr | 123 → 112 | 123 → 119 | 109 → 126 | 116 → 115 |
records | 220 → 226 | 225 → 226 | 189 → 195 | 188 → 194 |
selective on 8 and 22 threads and ssr on 8 were rerun with 20 runs each and came out level (selective 46–50 ms both ways on 8 and 22 threads; ssr 134–141 → 135–139 ms on 8).
Two cases measured on the way, each with a fix:
- Two actors spawned together (
spinloops, 4 threads): a prototype rule taking work only from a thread with two actors queued ran them one after the other, 2.0 s against 1.1 s; now 1.14–1.20 s against 1.12–1.22 s (sched::tests::actors_spawned_together_run_in_parallelfails under the old rule). - The ring on one thread was 8–16% slower until the push path skipped waking when there is no other thread, and
run_slicewas inlined in the worker loop again (it had one caller before).
Consequences
- Latency within a slice, as before: a receiver waits for its sender's slice to end (at most 2,000 reductions), and is no longer taken by another thread meanwhile. A thread whose actor runs long holds its next slot that long; the queue behind it can still be stolen.
- An actor woken on a busy home thread waits for that thread's current slice, unless another actor is behind it in the inbound queue (then a searcher takes some). Moving the first one would cost its caches and remote frees; the alternative bound is Go's "steal the slot after 3 µs", not done.
- Idle threads sleep without polling, except the existing hibernation epoch timeout; a thread is woken only for work it may take.
- Verification: the runtime unit tests on 1 and 4 threads, the loom models (
scripts/loom.sh, now withpark), the native tests on 1 thread (exact output) and 4 (no leaks), the stress tests on 8 and 22 threads, ThreadSanitizer (scripts/tsan.sh: clean but fortests/run/table.lse, which fails the same way on 0.9.0, issue #419) and thecheckpart ofscripts/ci.sh.