Skip to content

render --at on a 3D composition costs time and memory in proportion to the frame index, not the frames asked for #77

Closed

Description

@shinyobjectz

raea render X.tsx --at N on a composition with 3D gets slower and bigger as N grows, even for one frame. Reported from a 3,618-frame 3D film (one Canvas3D: a few hundred parts, glTF, point lights, shadows, bloom, depth of field, outline, a look mode; no sound, video or Compute):

frames asked time peak memory
--at 30 9 s 3.1 GB
--at 1200 47 s 4.7 GB
--at 2448,2457 234 s 7.1 GB
--at 2448,…,2778 (6 frames) 286 s 9.3 GB
a 72-frame chunk of the same scene, one frame 12 s 3.0 GB

The workaround is to render stills from short chunk compositions (from = the chunk's first frame).

Small repro

200 cubes turning with the frame, a camera and a light, durationInFrames={3618}, on main:

--at peak memory
30 385 MB
1200 604 MB
2448 832 MB

A 2D-only composition of the same length doesn't grow: --at 3500,3600 takes 0.5 s and 381 MB.

Likely cause (from reading the code, not yet confirmed by a fix)

runtime/export/src/fed.rs scene_frames steps only the wanted frames and their neighbours when no <Compute> carries state, which is the right thing. But it then returns (0..max(wanted)+1), filling every frame in between with a clone of the nearest stepped scene. The 3D program (scene_program_checked → raea-render's IR) is then built over all of those frames, so its columns and the cloned scenes grow with the highest frame wanted. render.rs's still loop also rebuilds that program on the first frame when a camera sits in a page element.

Fix direction: build the stills' program from the stepped frames only, and map each wanted frame to its place in it when the engine is driven (engine_before/Engine::new_live), so the cost is per frame asked for, not per frame of the timeline up to it.

Activity

  1. atishay-kasliwal commented on Nov 9, 2026

    @atishay-kasliwal

    I'd like to work on this if you aren't already fixing it. I'd keep the sparse stills' scene rows compact and map the requested timeline frames to their program positions, including the previous-frame reads and the rebuild after camera layout. Stateful Compute would keep the full stepping path.

    I'll compare time and peak memory at frames 30, 1200 and 2448, plus a sparse multi-frame request, and check the rendered images against main. Does that scope fit what you had in mind?

  2. shinyobjectz commented on Nov 9, 2026

    @shinyobjectz
    OwnerAuthor

    Fixed in d4a00c6. Thanks for the clear report: the --at 30 against --at 2448 numbers pointed straight at the cause.

    A still at --at F only stepped React near F, but it held every frame before F as a copy. Each changing column was then keyed on all of those frames, and the timeline evaluated and stored every one of them. Now the timeline evaluates only the frames where some key's value can change, and a frame that nothing changes shares the frame before's columns. A column also keeps only the keys where its value differs from a neighbour's, which is exact under linear interpolation.

    On 200 turning cubes over 3618 frames, --at 2448 now peaks at 504 MB, against 829 MB before (1.32x the --at 30 peak, down from 2.14x). Engine open fell from 700 ms to 280 ms, and the frame is pixel-exact. bench/at-cost/check.sh checks both the memory ratio and the pixels.

  3. shinyobjectz commented on Nov 9, 2026

    @shinyobjectz
    OwnerAuthor

    Second half landed in 4b8157f. Thanks for the sample, which found it: the render sub-app was running on every frame stepped before the still.

    Every engine installs the plugin clock, because some Bevy plugin is always registered. So a still at frame F first rendered all F frames before it in full, about 90 ms each in the film. The engine now steps through earlier frames only when the scene holds something that carries state from frame to frame: a plugin's component or resource, Bevy's animation, time or states, or a physics-driven mesh. Bevy's own components such as Camera, NotShadowCaster and Bloom don't count, and neither do raea's own rows.

    Results:

    • The film's --at 2448 goes from 226 s to 20 s, with identical pixels.
    • A physics still (avian, --at 100) still steps all 100 frames.
    • bench/at-cost now also checks that a frame-pure still steps no frames before it.
  4. added a commit that references this issue on Nov 9, 2026
    d4a00c6
  5. added 3 commits that reference this issue on Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions