Repository navigation
@remotion/web-renderer: Release unused CSS raster images between video frames - #13748
alec-watts wants to merge 1 commit into
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
ℹ️ No blocking issues — one non-blocking tradeoff noted below.
Approach: sound — eviction runs once per frame after createLayer() has fully resolved, and every consumer (getBackgroundFill, handleMask, createCssMask) has finished with its bitmap or blob by then.
Reviewed changes
Reviewed the per-frame raster cache eviction in the web renderer and every place that reads from that cache.
- Per-entry usage tracking.
getRasterImageResourcemarks cache hits and new loads asusedThisFrame, and the rejection cleanup now removes an entry only if it is still the current one for thatsrc. finishFrame()eviction. Entries that were not used during the frame are removed fromcacheand their bitmaps are closed. Bitmaps are first removed fromimages, so[Symbol.dispose]cannot close one a second time.- Call site.
renderMediaOnWebcallsfinishFrame()straight aftercreateLayer()resolves and before encoding.renderStillOnWebonly draws one frame, so it does not need the call and keeps the existing dispose-only behavior.
I confirmed that no ImageBitmap or CanvasPattern outlives the createLayer() call. drawableBySvg in turn-svg-into-drawable.ts is keyed per SVG and stores the data URL string, not the bitmap. Frames render one after another, so an entry that was not used this frame is never still loading when it is evicted. Deleting the current key while iterating a Map with for…of is safe.
Non-blocking
- Images that a composition cycles through are now fetched and decoded again on each cycle. Take a flip-book animation that loops through a small set of URLs via
background-imageormask-image(A → B → A → B…). Before this change every image stayed cached. Now each URL is evicted on the first frame it is not used, then fetched again and passed throughcreateImageBitmapthe next time it appears (finishFrame). The PR description accepts this tradeoff, and the HTTP cache absorbs most of the network cost. If it shows up in profiles, keeping unused entries for a few frames before evicting them would keep the memory bound and avoid the repeated decodes.
claude-opus-5-5 | 𝕏

A composition that changes its CSS background or mask URL across frames keeps each decoded ImageBitmap and its source Blob in the software renderer's cache until the entire export finishes. A long image sequence can therefore retain every earlier frame's image.
Track which entries the current video frame reads. Once the complete layer tree has drawn, evict entries the frame did not use and close their bitmaps. Layers sharing a URL and consecutive frames using the same image still share a decode. An image that disappears for a frame and later returns will be decoded again.
Verification
A local Chrome probe exported 32 frames through renderMediaOnWeb with one persistent background and 31 distinct PNG URLs. At the onFrame callback, live decoded bitmaps peaked at 31 with eviction disabled and at 2 with it enabled. The last frame held one bitmap, and render disposal closed it. Both runs decoded 31 images. The count tracks native ImageBitmaps with nonzero width. The existing Chromium background-image tests also passed.
Why each file changes