How tinyactors runs actors in your process

tinyactors is an embeddable C library that runs SCXML statechart actors inside your process from Node.js, Bun, Python, WebAssembly, and C. After reading, you can judge whether to depend on tinyactors and inspect its memory layout and compiled C core yourself.

Explore core's sourceOpen a snapshot

Actors run SCXML charts inside your process

An application handling order workflows needs explicit state machines without running a separate actor cluster or letting workflow logic open network sockets directly. A library that parsed XML or opened its own sockets behind the application's back would take that I/O out of the team's hands.

Each actor runs one SCXML statechart, which defines discrete states, transitions between those states, and a datamodel of variables. Instead of parsing XML at runtime, a compiler turns those charts into a binary image of .tai bytes. Your application embeds a host, which is the runtime instance that lives in your process and runs those compiled charts.

The engine inside that host never opens sockets, writes files, or sleeps on its own. Whenever an actor sends a message, writes a log, or invokes an external service, the host emits that request as an effect. Your application receives those effects, executes the I/O in Node.js, Bun, Python, WebAssembly, or C, and feeds events back. Because teams update statecharts over time, the next question is how one host loads compiled images and handles deploys.

A host runs one segment per image

A deploy during business hours must update an order statechart while existing orders are still waiting for payment. Stopping the process drops active workflows, and overwriting running definitions risks corrupting orders mid-transition.

Adding a compiled image to a host creates a segment, which is one running instance of that image inside the host. Inside each segment sits a system, the C engine that manages that segment's actors, mailboxes, and timers inside one memory block. Each segment assigns its actors unique session ids starting at k·2³²+1, where k is the segment index.

Adding an image that contains a chart of the same name performs a deploy. New actors start in the newest segment, while running actors stay on their existing segment until they end or migrate. To migrate an actor, the host moves it to the newer segment at a stable point while keeping its session id. The host also carries a system id, which identifies the whole host in addresses seen from other processes. Notice that the word system now names two distinct scopes, which the next section separates.

your process: Node.js, Python, a browser or C application storage and policy, I/O processors, services, the store for blobs host (ta_host) system id "shop", one clock, routing, versions, migration, the effects queue inputs: spawn, send, run effects: take, handle, ack segment 0 image A: order v1, payment retiring: an older version ta_system and its region sessions 1 to 2³²−1 segment 1 image B: order v2, payment current version of order ta_system and its region sessions from 2³²+1 segment 2 image C: chat-room ta_system and its region sessions from 2·2³²+1 migration: same session id a send inside the host another system another host, system id "billing" often another process or machine your transport: HTTP, a socket actor in memory actor waiting on a send hibernated: its record stays,its state is a blob
A process holds the application and one host. The host holds three segments, each a system with its own region of memory and its own range of session ids. An actor migrates from segment 0 to segment 1 and keeps its session id. A send to another system leaves through the application's transport.
WordWhat it isIn C
ImageCompiled charts, a .tai fileta_compile_charts
SegmentOne image running inside a host; segment k numbers its sessions from k·2³²+1ta_host_add_image
SystemA segment's engine: its actors, mailboxes and timers in one regionta_system
HostEvery segment as one actor system, with one clock and routingta_host
System idThe host's name in addresses, seen from other systemssystemID

System names two different things

An order actor in one process sends a payment request to a billing actor, while another actor talks to an external service in another process. Routing both messages through the same path either wastes network transport on local actors or traps external sends inside the host.

In the C library, a system is a ta_system struct, meaning one segment's engine inside a host. In actor addresses, a system is an entire host, named in addresses by its system id.

This distinction decides where messages go when one actor sends an event to another. When the destination address has the same system id, the host routes the event directly between its own segments. When the address names another system id, the send leaves the host as an effect for your application's transport. To keep that boundary strict across languages, tinyactors divides its C implementation into explicit layers.

A host owns one system per image

The host header says a host owns segments, one ta_system per image.

Segment k creates sessions k·2³²+1 to k·2³²+2³²−1, so a session id names one actor in the host.

Source:tinyactors, include/tinyactors/host.h

Another system is another host

A send to an address whose system id is not this host's leaves as an effect for your transport.

Sends between segments of one host stay inside the host.

Source:Other systemstinyactors, GLOSSARY.md

Each C layer calls only the layers below

A team needs the same statechart engine inside Node.js, Python, and WebAssembly without rewriting core rules per runtime. Tying the engine to libc, file handles or one host language would block embedding it in the others.

The modules base, image, trace, core, and system form the freestanding core, which never calls the C standard library. Core never allocates memory after its initial creation and never performs I/O. Instead, core reports side effects upward and calls back only into a datamodel evaluator and an allocator.

Above core sits the host layer, which coordinates multiple segments and allocates memory only through the allocator it is given. Above the host sit the SCXML compiler, datamodel engines such as quickjs for ECMAScript or a binding's own language, and bindings. Those bindings expose the host to Node.js, Bun, Python, WebAssembly, or C, while your application controls storage and policy. With core isolated from I/O, the next question is how your application drives the host during execution.

LayerWhat it doesWhere
CoreRuns statecharts over a compiled image, in one region sized at creationsrc/base, image, trace, core, system
HostRuns many systems as one, allocating only through the allocator it is givensrc/host
CompilerTurns SCXML documents into an imagesrc/compile
DatamodelsEvaluate expressions: ECMAScript on quickjs, or a binding's own languagesrc/datamodel_ecmascript
BindingTurns values into its language's objects and runs the looptinyactors-napi, tinyactors-cpython
ApplicationStores blobs and snapshots, and decides policyyour code

Effects leave in batches between runs

An order actor emits a payment charge and schedules a timeout before waiting for the payment gateway response in Node.js or Python. If the actor engine advances again before the host reads or handles those outputs, state diverges from real I/O.

Your binding or application drives the host in a loop: take a batch of effects, handle them, acknowledge, and run. A batch holds the outgoing sends, logs, and service invocations produced by the previous run.

Everything the host hands out with a batch, every field and every output, remains valid until your code acknowledges that batch. A run refuses while a batch is still open, so every effect of a batch is handled before any actor moves again. Once the application acknowledges the batch, the next run processes queued events and updates actors inside memory. The next section explains where that actor state lives inside memory.

A system keeps its actors in one region

A host running thousands of active actors and timers cannot afford per-actor heap allocations or raw pointers that break across process restarts. Unbounded allocations stall the event loop and prevent saving or moving actor memory as bytes.

Each segment stores all of its runtime state inside one contiguous block of memory called a region. At creation, the system partitions that region once into fixed pools for actors, events, timers, and requests. The same partitioning also sets aside slab pages for chart state and strings, an outbox, and a trace journal.

Records inside a region reference one another with relative offsets instead of raw memory pointers. Because offsets stay valid regardless of base address, the bytes of a region can be relocated or written straight to disk. When a pool fills up, the host grows the segment by allocating a larger block and copying the region into it. Knowing how a region is partitioned leads directly to the memory cost of each actor, message, and timer.

The region is carved once at creation

The system carves its header, actor slots, event slots, timers, slab pages, the outbox and the trace journal from one block.

Source:tinyactors, src/system/system.c, carve()

A full pool grows by relocation

When a pool runs out, the host copies the segment into a bigger block with more of that pool.

The capacity doubles until the block is a quarter larger, up to sixteen times the pool.

Source:tinyactors, include/tinyactors/host.h, "growth"

An actor's record takes 81 bytes

A team sizing a host for thousands of idle sessions needs exact per-actor memory costs before committing to production capacity. Guessing object overhead from runtime wrappers leaves teams blind to how quickly queued messages and timers fill RAM.

In the region pools, one actor uses 81 bytes, which includes the 48-byte ta_actor record, indices, links, and a generation byte. One queued message uses 106 bytes with tracing enabled, or 57 bytes when tracing is off. One delayed send uses 151 bytes with tracing enabled, or 102 bytes untraced, because it stores timer state alongside its message.

An actor's chart state and datamodel variables sit in slab pages or the datamodel engine on top of that 81-byte record. These byte counts come directly from C struct definitions and are verified by mise run layout against ta_system_layout. Because all active state lives in memory pools, you also need to know what a crash loses and how state persists.

One moreBytes, tracing onBytes, tracing offParts
Actor8181record 48, links 16, session index 8, name index 8, generation 1
Message10657event 56, trace context 48, generations 2
Delayed send151102timer 24, heap entry 20, generation 1, its message
From mise run layout in tinyactors-core on 2026-11-25, at commit 2dc827ac, checked against ta_system_layout.

A snapshot is the regions as bytes

A process crashes during peak traffic while actors hold in-progress orders in memory and thousands of idle sessions sit waiting for events. Without a way to persist individual actors or dump a whole host safely, a restart loses live state or risks restoring incompatible memory bytes.

A crash loses everything held only in memory, so only data written to your application's store survives. To persist idle actors individually, hibernation serializes an actor's state into a blob stored by your application. That actor's 81-byte record remains in the region so events and timers still locate it, and the next event wakes it.

To capture the entire host at once, a snapshot writes every segment's region, the compiled images, system id, and host time. A snapshot also stores datamodel state and a description of its memory layout with a hashed layout id. When restoring, the host checks that layout id and refuses a snapshot from a different layout instead of misreading bytes. Because the layout description travels with the bytes, the Inspector page and CLI can read snapshots without running the engine. For inspecting the C core itself rather than a saved snapshot, the page closes with Atlas.

  1. A support desk in tinyactors: 120 tickets, each an actor running a statechart, each open ticket watched by an invoked SLA timer.
  2. The workbench, tinyactors run, drives it on a simulated clock: tickets open, get triaged, assigned and answered; urgent ones breach their SLA.
  3. Last, run.snapshot writes the whole host to desk.snapshot: every segment’s memory, the chart images, the trace history, and a description of its own layout.
  4. The Inspector reads a snapshot in this browser tab, using only the layout description the file carries. Nothing is uploaded.
  5. desk.snapshot: 208 actors, the 120 tickets and the SLA timers they invoked, in one segment of 1.8 MB. Library and layout id come from the file.
  6. The segment’s region, byte for byte: the system header, then each pool, its generations, the indexes, the slab pages and the trace journal.
  7. One cell per actor slot, coloured by state: idle, runnable with an event waiting, hibernated to the store.
  8. Find a ticket by name. ticket-4161 has a customer reply waiting in its mailbox.
  9. Its 48-byte record, field by field: links are slots of other pools, strings are read from the slab and the image.
  10. The queued event: customer.replied, its name read from the chart image’s event table.
  11. Its chart, decoded from the image in the snapshot, with the active states lit: open › waiting_on_customer.
  12. The transitions out of the active states, and how many tickets sit in each state across the host.
  13. Click a state to list its tickets: the 35 that an agent is working on.
  14. The trace history the snapshot kept: 3,709 records, spans as OpenTelemetry names them, from the spawn to the capture.
  15. Only the selected ticket: its spawn, every macrostep and microstep, each event that moved it.
  16. And Atlas, on the Architecture page: the same ta_actor record, drawn from the build’s debug information, byte for byte.
A support desk of 120 tickets runs in the workbench on a simulated clock and is written to a snapshot. The Inspector then opens that snapshot in the browser: its memory, a ticket's record and queued event, its chart with the active states, and the trace history up to the capture.

Snapshots are raw region memory

Snapshots are region bytes plus the datamodel's own state, and restore only on a build with the same layout.

Hibernation blobs stay with your store and are not part of a snapshot.

Source:tinyactors, tinyactors-core/docs/durability.md

Restores refuse a snapshot of another layout

Each snapshot describes every type, member, offset and size in its regions, with a layout id hashed from that description.

A restore compares that id with its own build's and refuses a different layout instead of misreading the bytes.

Source:tinyactors, tinyactors-core/docs/durability.md

Open a snapshotTake a snapshot

Atlas shows every type and call of core

Hand-drawn architecture diagrams of a C library cannot be trusted when compiler padding and inlining alter the real binary. Without inspecting the optimized build itself, struct sizes and hidden call paths remain guesswork.

Compiler optimizations change the binary by inserting struct padding and inlining functions across translation units. To reflect the actual compiled code, the mise run atlas task extracts DWARF debug information from an optimized build of core.

Atlas renders every core struct across 64-byte cache lines, starting with the 48-byte ta_actor record, with padding bytes shown. Selecting any function displays its callers, its callees, and the calls inlined by the compiler, grouped by C layer. Each dataset names the commit its data came from, letting you inspect core directly below.

Atlas draws each struct of tinyactors' C core to scale on 64-byte cache lines, padding included, starting with the 48-byte actor record. Each function lists its callers, its callees and the calls the compiler inlined, grouped by layer.

Atlas reads the build's own debug information

The mise run atlas task reads each function, call site and struct from the DWARF of core's optimized build.

Atlas names the commit its data was built from.

Source:tinyactors, tinyactors-core/mise/tasks/atlas