Small enough to use everywhere

A started actor takes about 530 bytes and a hibernated one about 120. Four million fit in one process, and each operation costs about the same at four million actors as at two.

Measure your deviceSee the costsSee the scaling

Measure it on your device

Pick a scenario and a population, and one host runs it in a Worker on this page.

A host on this device runs a colony of cells that eat, give food to neighbours, divide and die, or a fixed population of up to four million actors that wait, get events, message each other, sleep in a store or hold timers. Charts follow the actors alive, births and deaths, events a second, time per event and memory over the whole run.

Every cell in the colony runs this chart, and dies in one of its two final states.

cell.scxml
<?xml version="1.0" encoding="UTF-8"?>
<!-- A cell. Every simulated second it ages and burns one unit of energy.
     The light (urn:lab) feeds it now and then and names a neighbour. A
     cell with energy to spare gives some to that neighbour; one that has
     doubled its store divides, and the light spawns the daughter with half
     the energy. A cell dies of hunger, or of age when its life is over:
     both are final states, and the host removes it. -->
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
       datamodel="ecmascript" name="cell" initial="alive">
  <datamodel>
    <data id="energy" expr="20"/>
    <data id="age" expr="0"/>
    <data id="life" expr="60"/>
    <data id="first" expr="'1s'"/>
    <data id="neighbour" expr="0"/>
  </datamodel>
  <state id="alive" initial="hungry">
    <onentry>
      <send event="tick" delayexpr="first"/>
    </onentry>
    <transition event="tick" cond="energy &lt;= 1" target="starved"/>
    <transition event="tick" cond="age + 1 &gt;= life" target="aged"/>
    <transition event="tick" type="internal">
      <assign location="energy" expr="energy - 1"/>
      <assign location="age" expr="age + 1"/>
      <send event="tick" delay="1s"/>
    </transition>
    <transition event="feed" type="internal">
      <assign location="energy" expr="energy + _event.data.food"/>
      <assign location="neighbour" expr="_event.data.neighbour"/>
    </transition>
    <transition event="gift" type="internal">
      <assign location="energy" expr="energy + _event.data.energy"/>
    </transition>
    <!-- A neighbour that has died: the gift is lost. -->
    <transition event="error.communication" type="internal"/>

    <state id="hungry">
      <transition cond="energy &gt;= 30" target="thriving"/>
    </state>
    <state id="thriving">
      <transition cond="energy &gt;= 40" target="dividing"/>
      <transition cond="energy &lt; 30" target="hungry"/>
      <!-- Fed while it has energy to spare: it gives a fifth of the meal on. -->
      <transition event="feed" cond="_event.data.neighbour !== 0" type="internal">
        <assign location="energy" expr="energy + _event.data.food - Math.ceil(_event.data.food / 5)"/>
        <assign location="neighbour" expr="_event.data.neighbour"/>
        <send event="gift" targetexpr="'#_scxml_' + neighbour">
          <param name="energy" expr="Math.ceil(_event.data.food / 5)"/>
        </send>
      </transition>
    </state>
    <state id="dividing">
      <onentry>
        <send type="urn:lab" event="divide">
          <param name="energy" expr="Math.floor(energy / 2)"/>
        </send>
        <assign location="energy" expr="energy - Math.floor(energy / 2)"/>
      </onentry>
      <transition target="hungry"/>
    </state>
  </state>
  <final id="starved">
    <donedata><content expr="'starved'"/></donedata>
  </final>
  <final id="aged">
    <donedata><content expr="'aged'"/></donedata>
  </final>
</scxml>

An actor takes about 530 bytes

Each cell is the memory one more actor, message or delayed send adds to a process holding a million.

runtime, datamodelactor, startedactor, after an eventactor, hibernatedmessage waitingdelayed send pending
node, native532 B673 B118 B309 B353 B
bun, native601 B781 B93 B386 B448 B
node, quickjs1036 B1634 B92 B309 B358 B
bun, quickjs1041 B1645 B90 B313 B356 B
Measured 2026-11-25 on an Intel Xeon at 2.10 GHz, 4 CPUs, 16 GiB, Linux; Node.js 22.23.5 and Bun 1.4.1. A counter chart with one variable, messages of {"text": "hello"}, tracing on.

A host's fixed costs spread over its actors, so an actor costs less in a larger population.

10,000100,0001,000,0002,000,0004,000,000
per actor, started803 B720 B532 B510 B495 B
per actor, after an event1446 B870 B673 B654 B639 B
per actor, hibernated637 B269 B118 B100 B91 B
per message waiting602 B392 B309 B293 B285 B
per delayed send pending737 B489 B353 B338 B331 B
Node.js on the native datamodel, the same run.

Size a host

A host grows on its own, but each growth copies its memory. A host that will hold a known population is better sized for it.

size.mjsjavascript
import { Host } from '@tinyactors/node';

const N = 2_000_000; // actors
const R = 1000;      // resident at most
const room = 64;
const host = new Host([], { system: 'big', config: { system: {
  maxActors: N + room, maxEvents: 4096,
  instanceBytes: 2048 * (R + room), stringBytes: 16384 + 64 * (R + room),
} } });
console.log((await host.hostConfig()).system.maxActors);
host.close();
output
2000064

hostStats reports each pool's capacity, what it uses and its high water mark:

stats.mjsjavascript
import { compileCharts, Host } from '@tinyactors/node';

const compiled = compileCharts([{ name: 'idle.scxml', text: `
<scxml xmlns="http://www.w3.org/2005/07/scxml" version="1.0"
       datamodel="ecmascript" name="idle"><state id="waiting"/></scxml>` }]);
const image = compiled.image;
compiled.close();

for (const system of [{}, { maxActors: 1000 }]) {
  const host = new Host(image, { system: 'demo', config: { system } });
  const before = (await host.hostStats()).pools[0].actors;
  for (let i = 0; i < 1000; i++) host.spawn('idle');
  const after = (await host.hostStats()).pools[0].actors;
  console.log(`maxActors ${system.maxActors ?? 'default'}: capacity ${before.capacity}, ` +
    `then ${after.used} used, high water ${after.highWater}, grown: ${after.capacity > before.capacity}`);

  host.addImage(image);
  console.log('segments reported:', (await host.hostStats()).pools.map((pool) => pool.segment).join(', '));
  host.close();
}
output
maxActors default: capacity 64, then 1000 used, high water 1000, grown: true
segments reported: 0, 1
maxActors 1000: capacity 1000, then 1000 used, high water 1000, grown: false
segments reported: 0, 1

Twice the actors, the same cost

Each row times one operation of the API on two million actors and on four million. Each cell gives both costs and their ratio, and a test fails when a ratio passes 1.5.

operationunitnode, nativenode, quickjsbun, nativebun, quickjs
populate (spawn and hibernate)µs per actor10.88 → 10.56 (0.97)7.43 → 7.56 (1.02)7.52 → 7.81 (1.04)6.26 → 6.02 (0.96)
spawnµs per call5.25 → 5.19 (0.99)2.62 → 2.60 (0.99)4.11 → 4.16 (1.01)2.43 → 2.45 (1.01)
terminateµs per call0.867 → 0.786 (0.91)0.571 → 0.575 (1.01)0.952 → 0.893 (0.94)0.751 → 0.720 (0.96)
sendµs per call3.79 → 3.64 (0.96)1.90 → 1.77 (0.93)3.19 → 3.00 (0.94)2.12 → 2.06 (0.97)
sendManyµs per event3.98 → 3.86 (0.97)2.18 → 2.04 (0.93)2.87 → 2.83 (0.99)2.01 → 1.85 (0.92)
send (hibernated: woken from the store)µs per call32.27 → 27.93 (0.87)28.29 → 27.92 (0.99)24.71 → 25.96 (1.05)33.43 → 33.10 (0.99)
hibernateµs per call5.41 → 4.93 (0.91)4.21 → 4.17 (0.99)3.56 → 3.44 (0.97)4.07 → 3.86 (0.95)
wakeµs per call6.94 → 6.38 (0.92)3.90 → 3.69 (0.95)6.91 → 7.27 (1.05)4.19 → 4.43 (1.06)
actor (by name)µs per call3.96 → 4.01 (1.01)3.96 → 3.88 (0.98)1.32 → 1.20 (0.91)1.13 → 1.12 (0.99)
actorStateµs per call4.26 → 4.01 (0.94)4.15 → 4.11 (0.99)3.90 → 3.73 (0.96)3.66 → 3.58 (0.98)
hostStatsµs per call25.65 → 25.05 (0.98)24.49 → 23.49 (0.96)19.35 → 19.60 (1.01)18.96 → 18.23 (0.96)
I/O processor round tripµs per call10.11 → 10.16 (1.01)6.81 → 6.73 (0.99)7.09 → 6.87 (0.97)5.77 → 5.54 (0.96)
transport round tripµs per call30.55 → 31.31 (1.02)25.92 → 26.36 (1.02)25.19 → 26.15 (1.04)22.05 → 23.06 (1.05)
delayed send and its timerµs per call6.28 → 6.19 (0.98)3.09 → 3.01 (0.97)4.95 → 5.15 (1.04)3.35 → 3.37 (1.01)
invoked service round tripµs per call13.52 → 13.93 (1.03)10.33 → 10.12 (0.98)10.13 → 10.66 (1.05)9.15 → 9.79 (1.07)
sweep (every actor)µs per actor0.006 → 0.005 (0.87)0.006 → 0.005 (0.87)0.006 → 0.006 (0.95)0.006 → 0.006 (0.91)
migrate (one session)µs per call24.09 → 25.32 (1.05)16.51 → 16.95 (1.03)35.62 → 20.64 (0.58)16.90 → 16.30 (0.96)
snapshotµs per actor0.100 → 0.092 (0.92)0.079 → 0.084 (1.07)0.081 → 0.087 (1.08)0.101 → 0.092 (0.92)
restore (and its first turn)µs per actor0.291 → 0.298 (1.02)0.217 → 0.215 (0.99)0.223 → 0.217 (0.98)0.198 → 0.192 (0.97)
closeµs per actor0.114 → 0.128 (1.13)0.120 → 0.157 (1.31)0.126 → 0.127 (1.01)0.120 → 0.139 (1.16)
Most actors hibernated in SQLite, at most 1000 resident. Measured 2026-11-20 on an Intel Xeon at 2.10 GHz, 4 CPUs, 16 GiB, Linux; Node.js 22.23.5 and Bun 1.4.1. Microseconds.

Correct by the standard

The core passes the W3C's SCXML test suite, and every binding runs it too.

Every binding runs the same suite

The conformance suite runs the W3C tests and its own scenarios against each binding, on each of its datamodels.

Source:tinyactors-test, README.md