Skip to content

Preview: keep rendering past the cached frames after a loop or restart - #1920

Merged
aiongg merged 2 commits into
storytold:mainfrom
ded-achtung:g5-preview-prefetch
Oct 23, 2026
Merged

aiongg merged 2 commits into
storytold:mainfrom
ded-achtung:g5-preview-prefetch

Conversation

@ded-achtung

@ded-achtung ded-achtung commented Oct 20, 2026 •

Copy link
Copy Markdown

What you see

Play a comp that is only partly cached, stop, and play it again from the start (or let it loop). Rendering stops: the CPU sits idle and the green cache bar doesn't grow. It resumes only when the playhead is about 1.6 s before the end of the cached run. If rendering can't catch up from there, playback stalls.

Cause

While a preview plays, update_playback looks for uncached frames only within ahead * 3 frames of the playhead. ahead is twice the number of frame workers, so the window is 96 frames with 16 workers: 1.6 s at 60 fps. After a loop or a restart all of those are cached, so nothing gets queued.

Change

A playing preview now looks for the next uncached frames as far ahead as the RAM preview holds, capped at the length of the range. It still queues at most ahead frames at a time.

The far-ahead frames don't push out the near ones. When the cache is full, eviction removes the frames the playhead reaches last (#595, #793). While paused, the window is unchanged.

Measured

Windows 11, 16 threads, #1812 project at Quarter. The test: play from 0 for 12 s, stop, play from 0 again.

main this PR
CPU during the second play, 1–12 s 0.6 cores (idle) rendering continues
cached when stopped at ~13 s up to ~15 s up to ~105 s (the 3 GB RAM preview)

Test

playback_prefetches_past_the_cached_frames_ahead: frames 0–119 are cached (more than the widest old window), playback starts at 0, and a frame past 119 must render within the first second. On main the test fails.

Related

#1121 (open) fixes a different stall: the order in which prefetch frames finish. It touches cache_when_idle in the same file, so whichever lands second may need a small rebase.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Playback prefetching now starts at the first uncached frame within the available memory and preview range.
    • Playback continues rendering uncached frames beyond previously cached sequences during the initial second.
    • Prefetching now maintains an ahead window while respecting memory limits and the selected video mode.
  • Tests

    • Added coverage to verify playback prefetches frames beyond an existing cached sequence.

The playback prefetch only looked ahead*3 frames (96 with 16 workers) for uncached frames.
After a loop or a restart from the start those were all cached, so the workers stood idle until
the playhead came within that window of the end of the cached run, then the preview stalled.
A playing preview now looks as far ahead as the RAM preview holds (and the range spans) for
the next uncached frames, still queuing at most ahead at a time; eviction already spares the
frames the playhead reaches first (storytold#595).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 35967361-ad76-45b9-9d80-493b2b605130
📥 Commits

Reviewing files that changed from the base of the PR and between ff20f8e and ac5799b.

📒 Files selected for processing: 1
  • crates/ui-egui/src/lib.rs

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.

📝 Walkthrough

Playback prefetching now starts at the first uncached frame within the RAM-fitting playback range. It queues up to three worker-lookahead windows. A regression test verifies rendering beyond cached frames 0–119.

Changes: Playback Prefetch

Layer / File(s) Summary
Bound and validate playback prefetch
crates/ui-egui/src/lib.rs, crates/ui-egui/tests/ui_preview_align.rs
Playback prefetch resolves planned and work-area frames, finds the first uncached frame, and queues a bounded ahead window. The regression test verifies rendering beyond cached frames 0–119.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: claude

Merge Risk: ⚪ Minimal · up to ac579

Playback prefetch now resumes at the first uncached frame, so rendering continues after a loop or restart when nearby frames are already cached. No concrete merge-blocking risk is evident, and a regression test covers the new behavior.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly describes the main change: continuing preview rendering beyond cached frames after a loop or restart.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

🔧 Clippy (1.98.1)

Clippy execution timed out

Comment @coderabbitai help to get the list of available commands.

…head × 3 wide

Looking up to the whole RAM preview for uncached frames let the workers spread over the preview
while the playhead waited. On the GPU each worker then built a Classic 3D atlas for its own set
of layers, and on a cold start of the storytold#1812 project the device ran out of memory far more often
(first pass 1-56 % of real time instead of 63-81 %). The window now keeps its old width but
starts at the first frame ahead that isn't cached, so a loop or a restart still renders on at
once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ded-achtung

Copy link
Copy Markdown
Author

A correction to this PR, pushed as ac5799b.

The first version looked for uncached frames as far ahead as the whole RAM preview. On a cold start of the #1812 project with the GPU compositor, that made things worse. While the playhead waited, the 16 workers spread over the whole preview. Frames from different parts of the timeline have different sets of 3D layers, so each worker built a Classic 3D atlas of its own.

cold start from 0 s, 8 runs before this PR first version of this PR
first pass 63–81 % of real time 1–56 %
out-of-memory fallbacks 15 70+

My earlier measurements didn't catch it because they started from a warm cache. With Software Only both versions play at 99–100 %, so only the GPU path was affected.

The window now keeps its old width (ahead × 3) but starts at the first uncached frame ahead instead of at the playhead. A loop or a restart still renders on at once, and playback_prefetches_past_the_cached_frames_ahead still passes. The workers stay together. With #1917–#1919 and #1928, cold starts run at 94–98 % with no out-of-memory fallbacks.

🤖 Generated with Claude Code

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.

2 participants