Feature Library

Sim saves: a fixed-tick world that saves, loads and replays exactly

0.37 CPU ms
A still of the Sim saves: a fixed-tick world that saves, loads and replays exactly demo
Still
The live demo starts when it’s in view.Click a bed to sow or pick · Call rain · drag the timeline back, then Play on from here or Back to now · Quick save, Load and Check on the saves · Replay and check

The HaTac engine’s simulation clock and its portable save files, lifted out whole with no engine and no dependencies.

Game rules register as systems with their own rates (every tick, every third, every quarter second); the clock turns frame time into whole 1/60 s ticks at any frame rate and any speed from ¼× to 16×, with pause, single steps and an interpolation fraction for smooth drawing; every input is a journal entry at a tick, so replaying the journal from a checkpoint gives the same world, tick for tick. Each tick gets a 53-bit fingerprint, the whole world’s and each system’s, with clean systems skipped by a revision counter; firstSimDifference names the first tick and system where two runs part. Independent rules can sleep and settle a long gap in one call. A save is the recipes, the seed, the journal and a few packed checkpoints in one binary file (RSAV, CRC-32, gzip): a worker encodes it, stages it, reads it back and only then publishes it, keeping three verified generations in IndexedDB or a folder; version steps upgrade old files; replayCheck replays a file and names the first checkpoint that differs. Added in the library: one import, the engine’s defaults, a store in memory, hex fingerprints and thumbnail bytes. The demo is a walled kitchen garden with quick save, an autosave at dawn, loading with its hash checked, a timeline you drag back through, playing on from the past, and a replay that matches every tick until a careless rule breaks it.

What it costs a frame

0.37 ms
GPU
not used
CPU, median
0.37 ms
CPU, 95th pct
1.16 ms
Draw calls
0
Weight
Light

Measured 28 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 158, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged CPU 0.36–0.38 ms). What ran: Alone at 4×: the garden’s six systems (sky, cistern, twelve beds, 36 bees, the gardener, the market) stepped 240 ticks a second with every published tick fingerprinted (the clean systems skipped by their revisions), a checkpoint every 600 ticks (six kept), and the ledger, the fingerprints and the timeline refreshed four times a second. A quick save is pressed halfway: a thumbnail, the prepared capture, and the hand-off to the save worker (which encodes, gzips and writes to IndexedDB off the main thread). Phones: tiers are being measured next.

How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference

Typical frame ?
16.43 ms
1% low ?
56 fps
Varies by ?
±0.35 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
p50p95p9916.02 ms17.70 ms +
How long each frame took. Most frames sit in the tall bars; a long tail to the right is hitching.

Frames run on a 60 Hz timer (a page demo), so most frames take about one tick, 16.7 ms: the spread around it is what matters.

Frames

Median (p50) ?
16.43 ms
p95 ?
17.10 ms
p99 ?
17.53 ms
Slowest ?
17.99 ms
Mean ?
16.51 ms
Standard deviation ?
0.35 ms
1% low ?
56 fps
0.1% low ?
56 fps
Hitches ?
0 of 600
Over budget ?
0 of 600

Main thread

Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.0 / 0.6 / 1.9 ms

Input

Interactions ?
3
Input to paint ?
1.9 ms, worst 8.4
Longest handler ?
under 16 ms

Memory

JavaScript heap ?
40.1 → 36.0 MB
Growth ?
-4.09 MB

Browser

JavaScript a frame ?
0.46 ms
All tasks a frame ?
1.22 ms
Layout / style ?
0.05 / 0.18 ms
Main thread busy ?
7%

Garbage collection

Collections ?
23 (22 minor, 1 major)
Pauses ?
10.3 ms in all, longest 2.6

What it needs

Renders with
DOM and CSSPlain DOM and CSS: every current browser.
Your browser
Runs hereNo WebGPU needed
Depends on
NothingNo other packages
With an agent
install("sim-saves")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up

What it’s for

  1. A city builder, factory or farming game whose world runs on fixed ticks, the same at 30, 60 or 144 frames a second and at 16× speed
  2. Quick save, autosave and load for a browser game, written off the main thread and never left half-written
  3. A replay of a whole session from its inputs, a rewind to any moment, or playing on from the past with the old future dropped
  4. Finding a desync: two runs (two players, a server and a client, a build before and after a change) compared tick by tick, with the first differing system named
  5. A regression test that replays a saved game and checks every checkpoint byte for byte
  6. Old save files that still load after the game changes, through version steps for the file, each recipe kind and each system
  7. A simulation for teaching or tooling where any moment can be revisited exactly

Pitfalls, in brief

  1. A replay only matches when the rules are pure functions of the state, the tick’s inputs and the tick’s own random().
  2. Keep Math.sin, Math.cos, Math.exp, Math.pow and their kind out of rules that must replay on other machines: the standard lets each browser approximate them differently. + − × ÷ and Math.sqrt round the same everywhere.
  3. Every value that can change a later tick belongs in a system’s snapshot columns: counters, inventories, timers, pending events, switches.
  4. Change hashed state only inside system callbacks: steps, commands and advance(). onPublishedTick runs after the hash, so a change made there is missed by the fingerprint and by a load from a checkpoint.
  5. With revision() (or columnRevisions()), bump the counter at every write site, including writes one system makes into another’s columns (the demo’s bees add pollen to the beds, and the market takes the hive’s honey).
10 more in brief
  1. Register every system before the first step, snapshot, save or hash read, and build a world for a load from the save’s own recipes and seed. load() then restores the nearest checkpoint, replays the journal and checks the hash; a mismatch throws, and the clock refuses to step until a snapshot is restored.
  2. Only independent rules may sleep: a sleeping rule’s advance() and its historical steps may touch only its own state, never read a neighbour or issue a command.
  3. Set maxTicksPerFrame for the fastest speed you offer.
  4. Size the hash history for the comparison you want.
  5. Make one save writer when the world opens and keep it: it reuses the worker’s copy of unchanged checkpoints and journal pages.
  6. Saves need a secure context, IndexedDB (or a directory handle) and Web Locks; the writer needs a module worker the page’s Content Security Policy allows (worker-src or default-src ’self’).
  7. Give each world its own slot, and each app its own database name.
  8. Register a migration for every recipe kind and system layout whose version you raise, and recompute an affected checkpoint’s hash with snapshotHistory(s).at(s.tick) after changing its bytes.
  9. Show the skipped generations loadGeneration returns: a checksum failure falls back to an older save, and the player should know they lost the newest.
  10. Playing on from the past is a new line: the demo builds it from the old line’s checkpoints before the tick, a fresh snapshot at it, and the journal up to it (with any inputs a rule issued at or before it for later ticks, such as the dusk that puts the bees to bed).
15 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Adapted from published work, named below.

Hannes Andersson: The HaTac engine’s simulation clock, save files, replay check and their tests (built for his game and proven there); the library’s additions and demo.

Glenn Fiedler, “Fix Your Timestep!”: The accumulator that turns frame time into fixed steps and the interpolation fraction between the last two, which the clock’s frame() and alpha follow.

simulationfixed timestepfixed tickgame loopdeterministicdeterminismlockstepreplayjournalcommand loginput logevent sourcingcheckpointssnapshotsrewindtime travelscrubbranchsave gamequick saveautosaveload gamesave filebinary format

Near it in the frame