Repository navigation
Hush idles under its 100 MB budget: chats' pictures are decoded small, and the window lets go of spare drawables - #296
Merged
Merged
Conversation
…indow lets go of spare drawables Chats' pictures went to GPUI as encoded images, which it decodes whole and keeps for good: a phone's 640x640 picture held 1.6 MB, and as much again on the GPU, for every chat in the list. They are now decoded off the window's thread with their shorter side at most 128 px (Group Info's 64pt at 2x), 64 KB each. On macOS GPUI's Metal layer keeps every window-sized drawable a run of frames needed (five after the launch's Connecting spinner, 11 MB each at the default size), hidden or not. A second after the window last drew, once another app is in use and after each minute's redraw, a drawable size set and set back empties that pool; the frame shown stays. Measured with 60 chats with pictures: 330 MB idle before, 62-72 MB after.
…r drew, and a picture that doesn't decode is logged Review fixes. The quiet check raced the frame its own trigger draws (the redraw after going behind another app, the minute's redraw): whether the drawables went came down to timer lateness. A window behind another app now lets go a second after, whatever it still draws (a blinking caret); one in front waits once more for the frame just asked for, then lets go if quiet. The last frame's time is on the executor's clock, which window tests drive. A chat picture that doesn't decode is logged by its file's name, as GPUI's loader did before. The shorter side is rounded up, a missing Metal layer is said once, and comments say what the code does.
# Conflicts: # core/Cargo.lock # core/desktop/Cargo.toml
Owner
Author
Review (
|
This was referenced Nov 29, 2026
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.
Hush idled at ~190 MB on the owner's Mac against a 100 MB budget. Two things held most of it, and both are fixed here.
What changed
Chats' pictures are decoded at the size of their largest drawing (
files::avatar,load_pictures). The chat list handed each picture to GPUI as an encodedImage, and GPUI decodes those whole and keeps them for good. A phone's 640×640 picture took 1.6 MB of pixels, plus the same again for its GPU copy. The chat list isn't virtualized, so every chat with a picture paid this, on screen or not. Now each picture is decoded off the window's thread so its shorter side is at most 128 px: the largest one drawn (Group Info's, 64pt) at 2×, the scale the bubbles and stickers already use. That's 64 KB per picture, plus a 64 KB GPU copy. The shorter side is rounded up, so it is never a pixel short. A picture wider than 4:1 has its longer side capped at 512 px, so it draws a little soft; the circle crops it anyway. An animated picture shows its first frame, as the Mac app did, so a GIF picture no longer animates. A picture that doesn't decode shows its initials and is logged ("a chat's picture isn't shown", with the file's name, as the core logs it).image_formatand its test go away, since the decoder now decides what counts as a picture.macOS: the window lets go of its spare drawables (
app::drawables). GPUI's Metal layer keeps the window-sized drawables that a run of frames took, and keeps them while the window lives, hidden too. After the "Connecting…" spinner at launch, vmmap counted five "CAMetalLayer Display Drawable" surfaces, though GPUI asks for at most three: 2000×1442 BGRA, 11 MB each, at the default window size, and more for a larger window. Changing the layer's drawable size empties that pool, and setting it straight back leaves the frame on screen as it is. Hush does this at two moments:If GPUI's view ever stops having a Metal layer, this says so once in the log.
This reaches into GPUI's layer from outside, so it carries a
shortcut:comment: drop it once GPUI trims its own idle drawables. On Windows and Linux it does nothing.Measured
All numbers come from the bare release binary (
cargo build --release -p hush-desktop) withHUSH_DATA_DIRset to a throwaway folder. Memory isfootprint(Activity Monitor's Memory, the same astop -stats memandscripts/perf.sh), sampled every second or so after the window settled. Window: the default 1000×720 at 2×.For a realistic dataset without an account, I used a scratch harness that isn't committed. It makes 60 chats, each with its own 640×640 JPEG picture (120 KB on average), and loads them the way
load_pictureskeeps them: before, an encodedImage; after,files::avatar. It also starts out "Connecting…" for 2 s and then goes online, as a linked launch does. "Another app in front" means the harness deactivated Hush (NSApp.deactivate).Where the 60-chat "before" went: 147 MB of malloc (the decoded pictures) and 126 MB of GPU memory (their copies). Then 56 MB of IOSurfaces (5 drawables) and about 20 MB of everything else.
Checked and left as they were
spawn_call_routerspawns its thread on the first call message, and only while linked. Incoming offers still go throughensure_engine, and the existing router tests cover them. At rest it costs nothing, so nothing changed there.sqlite3MemMalloc). Not worth shrinking.What's left above 100 MB
Nothing at steady idle. It goes over only for a while, and only on macOS:
BlinkCursor(not measured): it hides the caret but still redraws the window twice a second. That redrawing was already there and isn't changed here. It keeps one or two drawables, not five. Letting the caret stop blinking after a while (CursorBlink::with_idle_timeout) would end both, but it changes how the caret looks, so that's a call for the owner.Tests
chats::window_tests::chat_pictures_are_held_no_larger_than_their_largest_drawing: a 640×640 picture read through a real core is held at 128×128, and GPUI never decoded it whole. It failed before the change ("GPUI decoded the whole picture").chats::window_tests::a_chat_picture_that_doesnt_decode_stays_unread_and_one_that_didnt_read_is_asked_again: guards the rewritten failure paths ofload_pictures. It passes on the old code too, since the behaviour is kept.files::tests::a_chats_picture_is_decoded_to_fill_its_circle: square, wide, tall, rounded-up, small and very wide pictures, plus a still-encrypted file that isn't one.drawables::window_tests(3): a window lets go a second after the frame its asker drew, not before; a window in front that keeps drawing keeps its drawables; a window behind another app lets go though it keeps drawing. Two of them failed before the review fix.drawables::tests::letting_go_keeps_the_drawables_size: emptying a realCAMetalLayer's pool leaves its drawable size as it was.make checkpasses on 3ba1450 (origin/main merged in):cargo fmt --check, bothclippy -D warningsruns, andcargo test --features hush-desktop/snapshot(402 + 553 passed, 4 ignored).--snapshot) looked at:typing-light/typing-dark. Bogdan's picture in the chat list (40pt) and the timeline's gutter (28pt) is sharp and fills its circle.Closes #276