Repository navigation
Decode local images on iOS at the size they're drawn - #151
Merged
simonhamp merged 1 commit intoOct 22, 2026
Merged
Conversation
NativeUILocalImage decoded every file at full size, so a 2400x1600 photo in a 318x212 pt frame took 15 MB, and the 64 MB cache held about four of them. Coil on Android decodes at the view's size. The view now measures its laid-out size with onGeometryChange, which changes nothing about layout, and asks the cache for an image big enough to fill that many pixels. The cache reads the file with UIImage(contentsOfFile:), so UIKit still picks the @3x sibling, the scale and the orientation, then decodes with preparingThumbnail(of:) when the frame is smaller than the file. The thumbnail keeps the full file's size in points, so an image laid out at its natural size or ratio doesn't move. There's still one cache entry per path. A file drawn at two sizes keeps the bigger decode and serves both. When a frame grows, the image already on screen keeps drawing until a bigger decode replaces it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
simonhamp
marked this pull request as ready for review
October 22, 2026 18:16
simonhamp
added a commit
that referenced
this pull request
Oct 22, 2026
* Load local images off the main thread on iOS NativeUIImageCache stat-ed the file on every body evaluation to build its key, and UIImage(contentsOfFile:) read and decoded the file on the main thread. A trace of a list of local images scrolling on a phone spent 0.78 s of 75 s there. The cache is now keyed by path, and the main thread only looks in memory. NativeUILocalImage shows a cached image straight away, otherwise a placeholder in the image's frame while the file is checked, read and decoded in the background. Rows showing the same file share one load, and a load is cancelled when every image waiting on it has gone off screen. Each appearance re-checks the file's modification date and size in the background, so a file overwritten in place still shows its new bytes. Co-Authored-By: Claude Opus 5.5 <[email protected]> * Decode local images on iOS at the size they're drawn (#151) NativeUILocalImage decoded every file at full size, so a 2400x1600 photo in a 318x212 pt frame took 15 MB, and the 64 MB cache held about four of them. Coil on Android decodes at the view's size. The view now measures its laid-out size with onGeometryChange, which changes nothing about layout, and asks the cache for an image big enough to fill that many pixels. The cache reads the file with UIImage(contentsOfFile:), so UIKit still picks the @3x sibling, the scale and the orientation, then decodes with preparingThumbnail(of:) when the frame is smaller than the file. The thumbnail keeps the full file's size in points, so an image laid out at its natural size or ratio doesn't move. There's still one cache entry per path. A file drawn at two sizes keeps the bigger decode and serves both. When a frame grows, the image already on screen keeps drawing until a bigger decode replaces it. Co-authored-by: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
simonhamp
added a commit
that referenced
this pull request
Oct 22, 2026
Brings in #149 (with #151), #152 and the final #145, plus everything else merged to main since #144. The four conflicts were all in files where combined's own changes (#145, #149, custom icons, the pager header and the sticky header) are now on main in their final form, so main's version wins. Combined still carries text-outline (#142) and the Android sheet handle on top of main. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Stacked on #149, so the diff here is only the downsampling. Retarget to
mainonce #149 merges.After #149, local images load off the main thread but still decode at full size. A 2400x1600 photo in a 318x212 pt frame takes 15 MB, and the 64 MB cache holds about four of them. In fast flings on the simulator, photos showed their placeholder for up to about 0.3 s. Coil on Android already decodes at the view's size. This does the same on iOS.
The change
NativeUILocalImagemeasures its laid-out size withonGeometryChangeand asks the cache for an image that fills that many pixels. Measuring doesn't change layout. Before the image arrives it measures the placeholder, which fills the element's frame, so rows still don't move.UIImage(contentsOfFile:), so UIKit keeps choosing the file, scale and orientation as before. It turns out it picks a[email protected]sitting besidename.jpgon a 3x phone. When the frame is smaller than the file, it decodes withpreparingThumbnail(of:), which is ImageIO's thumbnail decode with the orientation handled. Otherwise it does the same full decode as before.fitimages as well asfillones. A contained image whose frame is a different shape from the image can decode bigger than it's drawn, but never smaller. I went that way because a flexiblefitimage's placeholder doesn't know its final height, and decoding to fit that guess would give a blurry first frame and a second decode.Numbers
Same setup as #149: iPhone 17 Pro simulator (iOS 26.2), a 300-row
native:listof local JPEGs, cold launch, then 30 scripted flings. Before is #149 on its own.The main thread is unchanged from #149: one or two decode samples per run.
Each photo decode is slower on the simulator, though. The median went from 15.4 ms (full size) to 23.8 ms (954x636). In a standalone test the thumbnail decode costs about 20 ms against 12 ms for a full decode of the same file. Total decode time still drops by about half because there are far fewer decodes: the cache now holds about 26 of these photos instead of 4, so avatars and recently seen photos stop being thrown out. A phone has a hardware JPEG decoder, so the per-decode numbers could look different there.
Checked on the simulator
For review
mainapart from one unrelated icon line), with a local test screen in a clone of dev-null-app. Nothing from the test app is in this PR.swiftc -typecheck -wmoagainst mobile-air's NativeRender gives the same baseline errors as Load local images off the main thread on iOS #149 (core types outside that folder) and nothing new, with planted errors to prove the new code was checked. With-strict-concurrency=completethe only warning in the file is still the existingcachestatic.🤖 Generated with Claude Code