Rewind, ghost runs and replays for fixed-tick games
0.23 CPU ms
Still
The live demo starts when it’s in view.Watch it sail itself, or take over: arrows or WASD steer, up sheets in, down brakes; hold Space or R to rewind. Drag the timeline; Share and Watch replays
Three things a player loves, on the HaTac engine’s deterministic simulation clock (lifted at ee6d23e, with its play-on-from-a-past-tick call).
Rewind: hold a key and the world runs backwards tick by tick over the last few seconds, at any speed, then plays on from wherever you let go with new input; the clock keeps a keyframe every half second and a seek restores the one before and runs the journal on, so the state shown is exactly the state that tick had. Ghost runs: a pose track records what you draw each tick and reads between ticks, so your best lap sails beside you as a translucent ghost, rebuilt from its replay. Replays: the run’s seed, rate and every input change, a 16-bit fingerprint each second and the final 53-bit one, packed into a few hundred bytes and a code people can read out and type (Crockford base32: case and look-alikes forgiven, a CRC catches a typo) or a small file; watching one checks every fingerprint and names the second where it split. Headless and engine-free; works with any simulation you register as systems. The demo is an ice yacht racing a lantern slalom on a frozen lake at blue hour: the runners carve the run into the ice, and a rewind lifts the carve back out while snow rises and frost creeps in.
What it costs a frame
CPU
0.23 ms
02468101216.7 ms
GPU
not used
CPU, median
0.23 ms
CPU, 95th pct
1.00 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.21–0.23 ms). What ran: The module alone: 240 pucks (1,920 bytes of state) on the rewind clock, three seconds forward, then a seek every frame back through a second and a half at 2× (a keyframe restored, the retained keyframes copied, up to 30 ticks run again), then playing on with a nudge. Plain dots, no scene. Phones: tiers are being measured next.
NVIDIA GeForce RTX 4060 Laptop GPU · 13th Gen Intel(R) Core(TM) i9-13900Hmeasuring tool · 28 November 2026
not timed
1.18
1.72
Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.
How steadily it runs on RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · reference
Typical frame ?
16.85 ms
1% low ?
55 fps
Varies by ?
±0.49 ms
All metricsRTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900H · referenceHow 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.85 ms
p95 ?
17.77 ms
p99 ?
18.16 ms
Slowest ?
18.41 ms
Mean ?
16.91 ms
Standard deviation ?
0.49 ms
1% low ?
55 fps
0.1% low ?
54 fps
Hitches ?
0 of 600
Over budget ?
0 of 600
Main thread
Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.1 / 0.8 / 1.4 ms
Input
No input during this run.
Memory
JavaScript heap ?
33.1 → 31.8 MB
Growth ?
-1.31 MB
Browser
JavaScript a frame ?
0.41 ms
All tasks a frame ?
0.90 ms
Layout / style ?
0.00 / 0.00 ms
Main thread busy ?
5%
Garbage collection
Collections ?
5 (3 minor, 2 major)
Pauses ?
15.5 ms in all, longest 1.6
All metricsNVIDIA GeForce RTX 4060 Laptop GPU · 13th Gen Intel(R) Core(TM) i9-13900H · measuring toolHow 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.77 ms
p95 ?
17.77 ms
p99 ?
18.05 ms
Slowest ?
18.34 ms
Mean ?
16.83 ms
Standard deviation ?
0.48 ms
1% low ?
55 fps
0.1% low ?
55 fps
Hitches ?
0 of 600
Over budget ?
0 of 600
Main thread
Long tasks ?
0
Long frames ?
0
Event-loop delay ?
0.0 / 1.9 / 2.4 ms
Input
No input during this run.
Memory
JavaScript heap ?
34.7 → 34.1 MB
Growth ?
-0.63 MB
Browser
JavaScript a frame ?
1.32 ms
All tasks a frame ?
2.15 ms
Layout / style ?
0.26 / 0.07 ms
Main thread busy ?
13%
Garbage collection
Collections ?
14 (13 minor, 1 major)
Pauses ?
11.7 ms in all, longest 2.0
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("rewind-replays")Your coding agent reads its pitfalls and installs it through the library’s MCP server. Set it up
What it’s for
A rewind button in a racing, platforming or puzzle game: hold to run the last seconds backwards, let go to play on from there
Racing your own best lap, or a friend’s, as a translucent ghost beside you, with the lead or lag shown live
Sharing a run as a short code in a chat or a small file, which plays back tick for tick on another browser
A scrub bar over a run: drag back through it, see where each gate was passed, and take over from any moment
Checking a replay before trusting it (a speedrun, a high score, a bug report): every second’s fingerprint compared and the split named
A replay of the last few seconds after a goal, a crash or a kill, from the same journal the rewind uses
A bug report that carries the exact run that showed the bug, instead of a description of it
Pitfalls, in brief
Everything rests on the rules being deterministic: the same state and inputs make the same next tick, bit for bit.
Keep Math.sin, Math.cos, Math.atan2, Math.exp and Math.pow out of the rules if replays travel between browsers: the standard lets each engine round them its own way. + − × ÷ and Math.sqrt are exact everywhere.
Inputs go in through rewind.input(system, value), never by writing the state: only the journal is replayed.
Draw from the pose track, not from the state.
A seek restores the keyframe at or before the tick, copies the retained keyframes and runs up to keyframeEvery ticks again: its cost is about (state bytes × window ÷ keyframeEvery) copied plus that many ticks stepped, every frame a rewind is held.
8 more in brief
createRewind makes the clock and sizes its keyframes for the window, so register your systems on rewind.clock rather than making your own.
Nothing runs while scrubbing: frame() returns 0.
Inputs a rule issues for later ticks are causal state and survive a play-on (the engine’s saveBranch keeps them); inputs the player gave after the cut are dropped.
Use a whole number of ticks a second: a replay stores the rate as an integer and refuses a tickSeconds that is not 1 / hz.
The fingerprints in a replay are 16 bits a second and 53 at the end: a split is found within a second, and a forged replay that matches by chance is one in 65,536 a second.
A code is a few hundred characters for a minute of play (about two bytes an input change, two a second for fingerprints).
A replay names its game with a hash of ReplayShape.sim.
The clock’s fingerprint history is reset by every seek (a restore starts it afresh); the rewind keeps its own fingerprint every hashEvery ticks for replays.
13 pitfalls in full, the hook-up guide, the module source and its tests come with the part.
Where it comes from
Written for the library. Fully custom code.
Hannes Andersson: The HaTac engine’s simulation clock, its journal, checkpoints, fingerprints and branch call, and the rewind, ghost and replay parts written for the library.
Douglas Crockford, “Base 32”: The alphabet the replay codes use: no I, L, O or U, and look-alikes read as the digits they resemble.
An undo/redo history whose steps carry a few words, so the buttons say “Undo Move ‘Dune’”; one drag or one typing session is one step, and so is a drag of a…