Skip to content

feat(studio): frame prefetch window with generation-keyed cache#68

Merged
LeadcodeDev merged 1 commit into
mainfrom
feat/studio-frame-prefetch
Jul 19, 2026
Merged

feat(studio): frame prefetch window with generation-keyed cache#68
LeadcodeDev merged 1 commit into
mainfrom
feat/studio-frame-prefetch

Conversation

@LeadcodeDev

Copy link
Copy Markdown
Owner

Closes #67.

Goal: fluid preview — pre-render N frames ahead of the playhead into a bounded cache, re-primed on every modification, instead of rendering each displayed frame on demand.

  • Structural fix first: StudioModel.scenario/tasks become Arc snapshots — no rendering under the model lock anywhere anymore (frame handler, hit-map, baseline/diff paths); in-flight renders keep the old snapshot alive across reloads
  • Cache: 120 JPEG entries keyed (generation, side, frame); eviction purges stale generations first (only for sides whose expected generation is known — the inactive side is never wrongly purged), then farthest-from-playhead. Accepted agent refinement: side A keys on the baseline source hash, so watcher reloads keep A-frames warm and Set-baseline invalidates them
  • Prefetcher: singleton background thread polling a published target {current, playing, generation, side, Arcs}; window [cur..cur+30] playing / [cur-5..cur+30] paused, nearest-first with forward tie-break, pass aborted the instant the target changes; per-frame catch_unwind
  • Edit flow: generation bump → stale keys purged on insert → window re-renders around the playhead (the requested "regenerate the N frames"); cache hits serve bytes with zero lock and zero render

Tests: 12 new (TDD red-first): exact nearest-first ordering, boundary clamps, stale-generation-first eviction incl. the unknown-side guard, distance eviction, bounded cache with side separation. 357 total, all green.

Verify: cargo check -p rustmotion-studio ✓ · cargo test --workspace → 357 passed ✓ · cargo fmt --check ✓ · clippy gated ≤1 ✓

Preview frames are now pre-rendered ahead of the playhead instead of
strictly on demand:

- StudioModel.scenario/tasks become Arc snapshots — no rendering ever
  happens under the model lock anymore (frame handler, hit-map,
  baseline and diff paths all clone Arcs under a brief lock and render
  outside it)
- bounded frame cache (120 JPEG entries) keyed (generation, side,
  frame); side A keys on the baseline source hash so watcher reloads
  keep A-frames warm while Set-baseline invalidates them
- background prefetcher thread polls a published target and keeps
  [cur..cur+30] warm while playing, [cur-5..cur+30] while paused,
  nearest-first, aborting the pass as soon as the target changes; an
  edit bumps generation, stale keys are purged on insert and the
  window re-renders — cache hits serve bytes with zero lock and zero
  render
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(studio): frame prefetch window with generation-keyed cache

1 participant