tobogganSe connecter

louise

Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.

550 lignes · 61661 octetsBrut · Historique

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 selective receive ... after.
  • Each kind of reply can therefore have its own type: call replies, DOWN messages, timer ticks.

Sending messages:

  • send deep-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 Bytes and thread_safe FFI resources are not copied. They are promoted to shared, with an atomic count.

Send safety:

  • Static: a Send auto-trait is checked on Subject message types. ADTs are structural, function types are assumed Send, and Resource<t> is Send only when declared thread_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 endsMechanismWhat linked actors see
PanicPANIC unwindingan abnormal exit signal
Exit signaldelivered 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 typed call and cast) and supervisor are written in Louise in std.
  • supervisor supports 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 blocking runs 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 type call replies or DOWN messages, so they were replaced by Subject and Selector.
  • 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:

  • proc is an ordinary effect declared in std/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 proc itself. 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/run relies on it.

Exits follow Erlang:

  • Actors that trap exits receive an ExitSignal for every linked exit, normal ones included.
  • Other actors die of abnormal exits only.
  • Monitors get Down. Monitoring an actor that is already gone yields Down(_, 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:

  • Selector and rest_for_one (M6 part 3). A selector waits on several tags at once through the proc operation receive_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=1 runs one thread with the interpreter's ordering, so tests/run output 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 in louise_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_link is 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.
  • spawn followed by monitor can see noproc, 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 subject Down arrives on.
  • Version check: generated code passes the number of proc operations it expects to tl_root_cap, which stops with a clear message when the runtime was built for another number (a stale liblouise_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 mention Subject<m> with m known, m must not hold a Ref, nor a Resource<k> whose kind k lacks @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 a fn handler could be copied to another actor, where a final ctl would 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=1 there 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.
  • 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. A SeqCst fence 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:

ProgramThreadsShared queue, one lockThis revision
tests/bench/messages.lse (a 1,000-actor ring)1222 ms167 ms
81,333 ms679 ms
221,793 ms781 ms
tests/stress/actors.lse (100k actors)14,063 ms3,309 ms
8837 ms786 ms
221,605 ms737 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/run relies 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.
  • 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, sleep and receive timeouts 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.rs http_idle_timeout_under_load runs 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 Sleepers hand-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:

Program1 thread24822
messages, before61 ms138215300411
messages, after64 ms58605963
parallel (64 actors computing), before1183 ms541287159113
parallel, after1012 ms532278164104
tests/stress/actors.lse, before2248–2843 ms671–759316–345393–408405
tests/stress/actors.lse, after952–1053 ms434–495372–425438–485461–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:

Threads12481222
before891370348387400414
after882319297344355382
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.
  • messages ran 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, messages runs the same instructions before and after (298,754,197 against 298,753,201). One codegen unit is also 9% fewer instructions on messages overall (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)ThreadsContendedTime spent waiting, all threads
virtual time843% of 2.0 M1.4 s (run: 1.0 s)
2254%7.4 s (run: 1.4 s)
real time (a socket open)872%6.2 s (run: 1.5 s)
2269%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 Firing guard, taken with try_lock between 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=1 there 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.
  • 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 Firing guard 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.

Program1 thread8 threads22 threads
tests/bench/timers.lse (virtual time)145 → 133 ms (−8%)135 → 124 ms (−8%)167 → 147 ms (−11%)
pairs_big649 → 635 ms (−2%)687 → 611 ms (−11%)868 → 685 ms (−21%)
sleepers51 → 53 ms (+3%)67 → 59 ms (−11%)76 → 65 ms (−14%)
timers_rt170 → 155 ms (−8%)197 → 162 ms (−17%)245 → 202 ms (−17%)
pairs_big_rt899 → 697 ms (−22%)1,206 → 581 ms (−51%)1,442 → 720 ms (−50%)
sleepers_rt114 → 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, messages and parallel move 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_rt is 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 effects 25–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.sh runs ThreadSanitizer on the runtime's unit tests, then on native programs: every tests/run program 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 with LOUISE_CI_TSAN=1; it is opt-in because it needs a nightly toolchain with rust-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=thread but without TSan's function entry/exit hooks (-mllvm -tsan-instrument-func-entry-exit=0). The hooks do not pair up across musttail calls, so an endless tail-recursive loop (tests/run/process.lse's spin) overflowed TSan's shadow call stack. Memory accesses are still checked; reports show fewer C frames.
  • 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), and scripts/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/run program, 20 times each on 8 threads: the same exit status as one thread, with the leak oracle at 0.
  • scripts/stress.sh on 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), as receive already 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 the madvise for 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 a RwLock, with the number of actors in an atomic beside them. Listing every actor (when main ends, on a deadlock) sorts by pid, so the order stays the spawn order.
  • --features lock-stats now 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:

    BenchmarkChange
    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% and dict +4.7%, with the same instructions. Neither touches the table: their hot functions (mi_free and the program's tl_entry, which ThinLTO inlines runtime code into) moved alignment. Against main they 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:

  1. control;
  2. the right to fire timers;
  3. one timer heap;
  4. one actor's lock;
  5. 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 Resource any actor holding it may use: one actor reading while another writes, say. The second to park overwrote the first, which was never woken. And io_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_wait cleared it. An actor between its WouldBlock and its io_wait when 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_waiters holds the pids waiting on each socket; an event wakes them all, and io_unwait removes only its caller's. A socket has one token for both directions, so a reader may be woken by writability: it retries, finds WouldBlock, 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 to io_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 call relay(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-safe Resource, 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:

    TypeSend when
    Int, Float, String, Bytes, bytes.Builder, Pid, Subject<m>, Dynamicalways. These are values or handles; Builder and Array copy on write.
    Ref<h, a>never: it belongs to its region, in one actor.
    Resource<k>when the kind type k is marked @thread_safe.
    Array<a>, a tuplewhen their elements are.
    an ADTwhen 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 checking Cons.
    an existential constructoronly if it stores Send for the types it hides (where Send<s> on the constructor).
    a type variable, or a projection that does not reduceonly if a given says so: a where Send<a>, or one inferred into an unannotated function's scheme.
    a function typewhen its capture row is empty (below).
  • Its evidence is erased. A Send constraint 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.send requires Send<m>. Subjects themselves are always Send, so creating and receiving need nothing.
    • actor.start requires Send<s> of its initial state.
    • The functions that run in another actor are send fn (below): spawn's, spawn_link's and spawn_monitor's body, actor.start's handler, and supervisor.Child's start function.
    • Effect operations may therefore carry where clauses.
  • Errors keep code E0704, with a chain saying why: "Job has a field cache: Ref<h, Dict<String, Int>>, which belongs to its region". A missing given in an annotated generic function is E0402: "add where 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. send is contextual: a keyword only in a type, before fn; it stays a valid name everywhere else, as process.send needs.
    • A plain fn(a) -> b in a signature has a fresh capture row, generalized with the signature. It accepts any function, and its body cannot send it.
    • A plain fn in a type definition's field is Local: a value of that type is not Send. A message type that carries a callback says send 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 Send requirement, Send<t> is required: the closure is sent, so what it holds must be sendable;
    • otherwise, if Send<t> does not hold, the row gets Local.

    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.

  • Always Local: a closure that uses a handler's capability from where it was written (a label of its row whose instance is not Bound, ADR 0010), and resume. 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 root proc, clock, random, io and ffi.

  • Top-level functions used as values capture nothing.

  • Send<fn …> closes the capture row. A clash with Local is E0704, naming the capture: "this closure captures r: Ref<h, Int>, which belongs to its region".

  • Printing: a type prints send fn when its row is closed and empty, and fn otherwise. 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 fn that is a parameter's whole type gets a capture row the caller chooses. Every other plain fn (a result, a field, an alias, or a function type nested inside another type, including a parameter's List<fn…> or fn(fn…)) is Local. Generalizing a nested one would be unsound: a body could hand the caller a Local closure through a position the caller had chosen to be sendable (a Ref<h, fn…>, or a callback's argument).
  • An expected Local accepts any function. Where an expression is checked against a type (an argument, a field, a result), a function type whose row is Local takes any function without unifying rows: it is never sent, so what was captured does not matter. Values read back out of it are Local. This replaces the "no subtyping" mismatch for the common cases; it remains for functions inside other values (Some(f) where Option<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 Local because the inner row is still open.
  • A type variable nothing determines is Send: only polymorphic values have such a type, or what @extern code 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>) -> Msg is 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>. In std, that means actor, supervisor, http's connection actors, and user helpers like relay. Unannotated functions infer it.
  • Callbacks that cross actors are send fn: the spawn family, actor.start, supervisor.Child, and std/http's handler, which runs in each connection's actor. Code that passes a closure capturing a Ref or 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 fn is a type mismatch, because the field says Local and the send says empty. The error suggests send fn for the field. This is the price of keeping HM inference without subtyping.
  • Checking cost: one structural walk per distinct Send constraint, cached per type definition, as send.rs did. The generated code is unchanged: the evidence is erased, and capture rows are types only.
  • send.rs is 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.
  • Send without capture tracking: function types assumed sendable, as before. It leaves the commonest runtime crash, a spawned closure capturing a Ref, to run time.
  • Function types never Send. Sound and simple, but it would refuse every spawn.
  • Effekt-style capture sets (rejected for effects by ADR 0010). They track which values are captured; Send only 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 fn and fn. 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.

  • ExitReason gains Shutdown (constructor 3): an actor asked to stop, not crashed. It is abnormal for links, like Killed (a linked actor that does not trap exits stops too, with Shutdown), and is never reported as a crash.
  • process.stop(pid), the fifteenth proc operation: a target that traps exits gets ExitSignal(self(), Shutdown) and decides when to return; any other stops with Shutdown at its next safe point, as with kill. kill is unchanged.
  • A root that stops with Shutdown ends the program with status 0.
  • Signals (std/os.signals) arrive as messages from the runtime, like Down: 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 sixteenth proc operation: it stops the monitor that monitor pid (or spawn_monitor) made, whose Down subject is down. No Down arrives on it afterwards; one that already arrived stays, and demonitor_flush drops it too. down must be the caller's (another actor's panics); any other pid, or a subject that is no monitor's, is ignored. Each Down is delivered under the lock that ends its monitor, so a demonitor never races one that is on its way. Across nodes it is tie op 16 (docs/wire-format.md, ADR 0072).
  • A Louise handler of proc needs a demonitor clause: it must cover all 16 operations (E0504), and generated code passes 16 to tl_root_cap's version check. A test double of proc written before #414 no longer compiles until it has one.
  • Selector is 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 only selecting may pair them. As a public record, a program could rebuild an entry with another subject's tag and read an Int as a String (SIGSEGV), with std alone. Building, matching or reading a Selector outside std/process is E0117.

Note — 2026-11-02: unlink, the seventeenth proc operation (#422)

  • process.unlink(pid) is the seventeenth proc operation, with Erlang's guarantee: once it returns, the link has no effect on the caller until a new link, and the caller's exit none on pid. An ExitSignal already 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). unlink removes 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's ExitSignal or its own exit, happens under the lock that removes the half, so it never comes after unlink returns, as a Down never comes after demonitor.
  • 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_link makes 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 17 and 18 (docs/wire-format.md, ADR 0072): the caller's half waits, unlinking, for the other node's acknowledgement.
  • A Louise handler of proc needs an unlink clause: it must cover all 17 operations (E0504), and generated code passes 17 to tl_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_one per push, notify_all in 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 (one Injector per 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, like std::thread's park and unpark), so work for one thread wakes that thread alone. Sleepers is 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 SeqCst fence, 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_one against 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. With LOUISE_THREADS=1 the next slot is not used, and the order is the interpreter's.
  • --features sched-stats counts 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 with LOUISE_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.

RunCPU per requestread p95read p99load average at start
0.9.0 (3 runs)1.06–1.22 ms10.6–11.5 ms118–130 ms2.4–16.0
this revision (3 runs)0.86–1.05 ms6.3–8.9 ms50–67 ms5.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 ms7.5–8.2 ms43–56 ms17.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:

Program1 thread4822
messages (ring)48 → 4649 → 4749 → 4951 → 49
fanin80 → 80127 → 129131 → 126158 → 154
parallel908 → 882243 → 241134 → 13594 → 88
churn109 → 10676 → 7483 → 84116 → 117
timers127 → 12973 → 7072 → 7085 → 86
idle667 → 683865 → 845953 → 9391261 → 1203
selective36 → 3841 → 4147 → 5344 → 52
ssr123 → 112123 → 119109 → 126116 → 115
records220 → 226225 → 226189 → 195188 → 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 (spin loops, 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_parallel fails 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_slice was 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 with park), 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 for tests/run/table.lse, which fails the same way on 0.9.0, issue #419) and the check part of scripts/ci.sh.