Retain recycled swapchain surfaces#355
Merged
jdm merged 1 commit intoservo:mainfrom May 6, 2026
Merged
Conversation
Contributor
Author
|
@jdm thanks for reviewing this! looks like the wayland build is flaking for unrelated reasons though |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi! My app is using Servo embedded and rendering high perf graphics into an offscreen canvas, and I noticed WebGL users were quickly eating large amounts of RAM until the process crashed. The app does not have this issue at all on Windows or Linux, only MacOS shows it. I traced it back to this code with Codex (gpt-5.5 xhigh), and with this change everything works perfect across all 3 platforms.
Summary
Keep recycled same-size swapchain surfaces in the pool across swaps instead of destroying all leftovers every frame.
Why
SwapChainData::swap_buffersalready reuses one matching recycled surface as the next back buffer, but then drains and destroys every other recycled surface at the end of each swap. For high-frequency WebGL producers, this creates continuous surface create/destroy churn even when dimensions are stable. On macOS, where these surfaces are IOSurface/CGL-backed, that churn can show up as rapidly growing graphics footprint in long-running embedders.The swapchain already owns these recycled surfaces and destroys them on
destroy; this change also clears them onresize, where stale dimensions should be discarded.Verification
cargo check --features chains