# ADR 0073: `std/table`, tables any actor reads without a message **Status:** Proposed (2026-10-30, issue #407); needs engineering review (#44). It adds shared mutable state to a language whose state otherwise lives in actors, and a second way values become shared (ADR 0002). ## Context toki2 keeps one notebook actor per owner. Every read asks that actor: a page costs several message hops, and at an equal 2,500 req/s it measured p95 3.9 ms / p99 18.6 ms against 2.1 / 3.5 ms for a design that read one shared value. Erlang answers this read path with ETS (`read_concurrency`) and `persistent_term`: any process reads the latest value under a key with no message, while one process keeps it current. Louise had no global or shared mutable storage: no registry, no table. It had the pieces: promotion of a value graph to atomic counts (`send.rs`, ADR 0002's "promoted to shared"), type-erased generic externs, and an interpreter that runs every actor on one thread. ## Decision ```louise pub opaque type Table pub fn new :: -> Table / pub fn get :: table: Table key: String -> Option / pub fn put :: table: Table key: String value: v -> () / where Send pub fn remove :: table: Table key: String -> () / ``` - **Values are shared, never copied.** `put` makes the value shared with `send::share`, a new entry point that promotes the whole graph even when the root's count is 1 (`transfer` would move a unique value, leaving a non-atomic count other threads would race on). `get` retains the stored value; every reader holds the same blocks. A value that cannot be shared panics in the writer, as a send does; `where Send` makes that a compile error in typed code. - **A reader can't race a reclaim.** The map is 64 shards, each a read-write lock over the entries. `get` retains the value before it releases the read lock; `put` and `remove` release what they replace only after releasing the write lock. A reader therefore always holds its own count before a writer can drop the map's. - **Tables are immortal.** A table is an id (an `Int`), never freed, so no finalizer has to release Louise values (resource finalizers can't). Entries are released on replace and remove; what a program leaves in a table at exit is still alive then. - **Effects:** all four operations are ``, and none is `pure()` in the extern table, so fusion never moves or drops a read. - **`put` consumes its arguments** (`owned`, in the extern table and the declaration). - **Interpreter:** a map in the interpreter's state; one thread runs every actor, so values are stored as they are; `put` refuses unsendable values like `send`. ## Consequences - A read is a shard lookup and an atomic increment, from any actor, in parallel with other reads. - Writers to one shard serialize; the 64 shards keep unrelated keys apart. - Shared mutable state is visible to every actor holding the table. Programs keep one writer per key (an owning actor), as with `persistent_term`; the table does not order concurrent writers. - Tests: the runtime's scenarios check exact counts (no live block left) for put, get, replace and remove, and `share`'s promotion and refusal; `tests/run/table.lse` runs on both backends (replace and remove while a reader keeps a value, two tables apart, 32 actors reading while one writes 2,000 times); `tests/ui/table_send.lse` checks the compile-time refusal; the program is clean under AddressSanitizer and UBSan on 4 threads. - **Counts are read atomically** (2026-11-01). Tables are the first place many actors dup and drop the same shared value at once, and ThreadSanitizer found the fast paths' plain read of a count (`tl_dup`, `tl_drop`, `tl_is_unique`, `dup_value`, the drop and send walks) racing with other threads' atomic updates. Every read that can see a shared block now goes through `tl_rc` (louise_rt.h) or `heap::rc`, a relaxed atomic load, which is a plain load on x86-64 and aarch64; writes stay plain, as only a local count's one owner writes it. Under TSan the last release takes an acquire load in place of its fence, as `Arc` does, since TSan does not model fences. Cost on `tests/bench` (instructions, one thread): +0.09% to +0.14% with the `fast` runtime, −0.05% to −0.30% with `lto`. `scripts/tsan.sh` is clean, `tests/run/table.lse` included.