mirror of
https://github.com/storytold/effectcraft.git
synced 2026-10-30 04:57:54 -06:00
Problem: pressing play on frames that still had to render left the playhead standing still for seconds. The cache bar showed a gap of a few frames right after the playhead while frames further ahead turned green, and playback started only once the whole prefetch window was cached. The earlier #595 change (prefetch order, eviction) started the right frames first, but they still finished last. Cache Frames When Idle left the same late-filling gaps. Cause: prefetch frames render side by side on one rayon pool, and each frame's own parallel loops run on that pool too. An idle thread steals a piece of a frame that is rendering; when that piece waits on a nested parallel loop, the thread picks up a queued frame job instead and renders queued frames until the queue is empty. Only then does it return to the piece it stole, so the frame that piece belongs to cannot finish while frames keep being queued. The frames started first are the ones just ahead of the playhead. Fix: the frames of a playing preview and of Cache Frames When Idle render on lanes: one single-thread pool per frame thread, one frame at a time each. A lane's thread only ever works on its own frame, so no frame waits under another. The shared pool keeps the viewer's frame, which still uses every thread, and the few frames prefetched around it while paused. Queued frames change hands when a preview starts or stops, or when the viewer shows one. Idle caching takes every lane instead of half the pool's threads. Tests: frames_started_first_are_done_first (a playing preview, idle caching) and queued_frames_render_when_a_preview_starts_or_stops. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>