Repository navigation
renderer: release GPU resources for hidden surfaces (macOS) - #14017
Merged
Merged
Conversation
Ref #12034 This commit releases many GPU resources when a surface becomes invisible and rebuilds it on the next draw. I don't say "all" because there are still some things we can improve on (Kitty images). We previously held onto all GPU resources for the lifetime of the surface regardless of its visibility state. This is 3x (for triple-buffering): screen render targets, uniform/cell/custom shader buffers, font textures, and more. Measured on macOS (Metal): | Measurement (1 visible + 20 hidden tabs) | Before | After | |---------------------------------------------|-----------|---------| | Tracked GPU allocations (steady state) | 384.6 MiB | 18.3 MiB | | `MTLDevice.currentAllocatedSize` | 393.3 MiB | 19.7 MiB | | `footprint` IOSurface (dirty) | 309 MB | 15 MB | | Swap chain rebuild on unhide (42 switches) | n/a | avg 0.43 ms, max 0.55 ms | As you can see, importantly, swap chain rebuild is fast: 0.43ms average. That means that the rebuild is imperceptible and happens well within a frame draw time. This is macOS only, but most of the work was in the generic renderer. GTK only needs to call `releaseGpuResources` when it becomes invisible to get the same benefits. I didn't have my VM handy to test this yet so I didn't include it.
wesm
pushed a commit
to kenn-io/ghosthub
that referenced
this pull request
Sep 1, 2026
- Reduce long-lived Ghosthub memory retention while pinned to libghostty 1.3.1. - Release Metal and IOSurface resources while terminal surfaces are hidden, without detaching tmux or SSH clients ([Ghostty #14017](ghostty-org/ghostty#14017)). - Track terminal page ownership explicitly and return free-listed page memory to the OS instead of retaining the process high-water footprint ([Ghostty #13241](ghostty-org/ghostty#13241), [Ghostty #13245](ghostty-org/ghostty#13245)). - Build on the ten upstream lifetime fixes already merged in #220; record the exact upstream commits and bump the bootstrap schema so stale artifacts rebuild. - Keep the v1.3.1 adaptation limited to hidden-surface semaphore and display-link APIs; the page-list source changes match upstream. - Allow local debug builds to be inspected with macOS memory tools; packaged release entitlements remain unchanged. - The patched libghostty passes its focused PageList tests, Ghosthub’s full Swift and Python suites, formatting checks, and the app build. Co-authored-by: CL Kao <clkao@users.noreply.github.com>
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.
Ref #12034
This commit releases many GPU resources when a surface becomes invisible and rebuilds it on the next draw. I don't say "all" because there are still some things we can improve on (Kitty images).
We previously held onto all GPU resources for the lifetime of the surface regardless of its visibility state. This is 3x (for triple-buffering): screen render targets, uniform/cell/custom shader buffers, font textures, and more.
Measured on macOS (Metal):
MTLDevice.currentAllocatedSizefootprintIOSurface (dirty)As you can see, importantly, swap chain rebuild is fast: 0.43ms average. That means that the rebuild is imperceptible and happens well within a frame draw time.
This is macOS only, but most of the work was in the generic renderer. GTK only needs to call
releaseGpuResourceswhen it becomes invisible to get the same benefits. I didn't have my VM handy to test this yet so I didn't include it.