Repository navigation
Shrink large images off the UI thread - #20
Draft
toddbeauchamp wants to merge 1 commit into
Draft
toddbeauchamp wants to merge 1 commit into
toddbeauchamp wants to merge 1 commit into
Conversation
Paint used to box-filter an oversized image inline the first time it was drawn at each downscale level, which took 11 ms for a 2048px avatar on an M5 Max. Images over 128x128 pixels are now shrunk on the background executor, every frame at once. Until the copy is uploaded, paint draws the nearest copy already in the atlas, or nothing, and the views that painted the image are notified when it lands. drop_image cancels a pending copy. The filter itself is about 5x faster with bit-identical output: fixed-size 2x2 blocks over chunked rows, and no per-channel division for fully opaque blocks.
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.
Follow-up to #19 (stacked on it): large images are now shrunk off the UI thread, so the first frame that draws a big avatar no longer drops.
Window::paint_imagebox-filtered an oversized image inline, inside the atlas upload, the first time it was drawn at each downscale level. That was 11 ms for a 2048px avatar on an M5 Max, a dropped frame at 60 Hz, and slower Windows machines are worse.downscale_levelcache key,drop_imagefreeing every level (it now also cancels a pending copy), andhas_image_atlas_entryreporting what is in the atlas.Timing
Filter time, release build, M5 Max, best of 30, shrinking to 32px:
Images with transparency run about 30% slower than opaque ones on the new path (2.66 ms at 2048px). Paint itself now only does an atlas lookup and a task spawn for these images.
Testing
elements::imgtests: first paint draws nothing and the next frame after the task draws a 32px tile; a resize keeps the 256px copy until the 32px one is ready;drop_imagecancels a pending copy; an animated image gets every frame's copy at once; a 128px image is still shrunk during paint; a cached child view repaints when its copy lands (fails if the notify is removed).cargo test --workspace,cargo clippy --workspace --all-targetsandcargo fmt --all --checkpass on macOS.run_until_parkedbetween them, which covers decode plus shrink, so badges and avatars still appear in captures.