# Performance Mode RenderMirror Prototype

This standalone prototype models the presentation-side mirror described in the performance-mode
plan. It is not wired into `SimulationEngine`, workers, buses, or public API entry points.

## Message Types

- `mirror.snapshot`: full mirror bootstrap. Carries `generation`, `baseTick`, `tick`, `sequence`, and
  ordered tables. Schema-generated mirrors may also include a per-table `generations` map that tracks
  entity lifetime generation separately from stream generation.
- `mirror.patch`: ordered batch of entity operations. Carries `generation`, `baseTick`, `tick`,
  `sequence`, and `ops`. Entity ops may carry `entityGeneration`.
- `mirror.upsert`: table/entity upsert message carrying `generation`, `baseTick`, `tick`, `sequence`,
  `table`, stable `id`, `value`, and optional `entityGeneration`.
- `mirror.fieldPatch`: table/entity field patch message carrying `generation`, `baseTick`, `tick`,
  `sequence`, `table`, stable `id`, `fields`, and optional `entityGeneration`.
- `mirror.remove`: table/entity remove message carrying `generation`, `baseTick`, `tick`, `sequence`,
  `table`, stable `id`, and optional `entityGeneration`.
- `mirror.generationReset`: clears the mirror and moves to a new generation.
- `mirror.rebaseFromTick`: clears the mirror and rebases from `baseTick`, optionally with replacement
  table contents.

Patches apply only when `generation`, `baseTick`, and `sequence` line up. Duplicate patch sequences
are idempotent only when the payload is byte-equivalent by stable stringification. Sequence gaps,
generation mismatches, and base-tick mismatches fail loudly and require rebase.

Stream `generation` is not entity lifetime. When `entityGeneration` is present, field patches and
removes must match the existing row lifetime or fail with a rebase-required error. An upsert with a
different entity generation is treated as a deterministic same-id new lifetime.

## Presentation Reconciliation

`reconcilePresentationObjects(mirror, tableName, presentationById, hooks)` is the renderer sketch:

- `hooks.create(id, row)` creates renderer-owned objects.
- `hooks.update(object, row, id)` updates renderer-owned objects from mirror state.
- `hooks.destroy(object, id)` destroys renderer-owned objects for removed rows.

The helper consumes mirror rows only. Mirror rows are cloned and frozen, so renderer-side objects
cannot mutate canonical simulation state through the mirror. When mirror rows carry an entity
generation, the presentation map key includes that lifetime so same-id respawns create new renderer
objects instead of patching the old lifetime.

## Audio Guidance

One-shot audio uses rollback-confirmed stable keys before playback. Continuous audio is desired-state reconciliation only, never direct playback from live simulation or re-sim.
