Skip to content

@remotion/web-renderer: Release unused CSS raster images between video frames - #13748

Open
alec-watts wants to merge 1 commit into
remotion-dev:mainfrom
alec-watts:codex/release-unused-raster-images
Open

alec-watts wants to merge 1 commit into
remotion-dev:mainfrom
alec-watts:codex/release-unused-raster-images

Conversation

@alec-watts

Copy link
Copy Markdown
Contributor

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

File Reason
packages/web-renderer/src/drawing/raster-image-loader.ts Record raster use and release evicted resources through their existing owner.
packages/web-renderer/src/render-media-on-web.tsx Finish the cache frame after the complete layer tree has drawn.

@vercel

vercel Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
bugs Ready Ready Preview Dec 2, 2026 9:40pm UTC
remotion Ready Ready Preview Dec 2, 2026 9:40pm UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T21:39:19.769488Z b31f337 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ 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. getRasterImageResource marks cache hits and new loads as usedThisFrame, and the rejection cleanup now removes an entry only if it is still the current one for that src.
  • finishFrame() eviction. Entries that were not used during the frame are removed from cache and their bitmaps are closed. Bitmaps are first removed from images, so [Symbol.dispose] cannot close one a second time.
  • Call site. renderMediaOnWeb calls finishFrame() straight after createLayer() resolves and before encoding. renderStillOnWeb only 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-image or mask-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 through createImageBitmap the 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.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

This branch was successfully deployed

2 active deployments
Preview – remotion — b31f3378 Deployed Dec 2, 2026 by vercel[bot]
Preview – bugs — b31f3378 Deployed Dec 2, 2026 by vercel[bot]
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.

1 participant