# Performance Mode StateBackend Prototype

This prototype defines an engine-facing seam without integrating it into `SimulationEngine`.

## API

```js
backend.beginStep(tick);
backend.endStep(tick);
backend.saveAnchor(tick);
backend.restoreAnchor(tick);
backend.rollbackTo(tick);
backend.snapshot();
backend.hashAt(tick);
backend.checkpointAt(tick);
backend.pruneBefore(tick);
```

`backend.state` is the current mutable canonical state during a step. It is canonical-only: no
wrappers, render mirror objects, workers, buses, transport payloads, DOM, audio, or renderer objects.

## Implementations

- `FullSnapshotStateBackend`: oracle backend. It stores full canonical snapshots after each step and
  restores rollback targets by cloning retained snapshots.
- `TrackedPatchStateBackend`: patch backend. It uses the standalone tracked-state prototype for
  mutation-time reverse patches and rollback, while still serving full canonical anchors through
  `saveAnchor()` and `snapshot()`.

Both backends compute `hashAt()` from canonical snapshots using stable key ordering. Hashes are not
derived from forward patches or render output.

## SimulationEngine Mapping, Not Integration

The intended mapping to existing engine concepts is:

- engine tick start -> `beginStep(tick)`
- deterministic game step mutates `backend.state`
- engine tick end -> `endStep(tick)` and `checkpointAt(tick)`
- retained full save point -> `saveAnchor(tick)`
- full restore path -> `restoreAnchor(tick)`
- rollback correction -> `rollbackTo(tick)`, then deterministic re-simulation through `beginStep` /
  `endStep`
- finalization/retention cleanup -> `pruneBefore(finalizedTick)`

This file is documentation for the prototype seam only. It does not change `SimulationEngine`, public
API behavior, worker loading, buses, render mirrors, bootstrap, or recovery.
