Repository navigation
perf(preview): shrink with Imaginary before rotating - #65483
Open
martin-rueegg wants to merge 1 commit into
Open
martin-rueegg wants to merge 1 commit into
martin-rueegg wants to merge 1 commit into
Conversation
martin-rueegg
requested review from
Altahrim,
come-nc,
icewind1991 and
sorbaugh
and removed request for
a team
October 13, 2026 19:59
CarlSchwan
approved these changes
Oct 14, 2026
martin-rueegg
force-pushed
the
perf/imaginary-shrink-before-rotate
branch
from
October 14, 2026 08:32
d9548fe to
9a0876b
Compare
Contributor
Author
|
Thanks, @CarlSchwan, for the review! PR has been rebased and force-pushed. Tests: ImaginaryTest passes on the rebased branch (11 tests, 47 assertions). |
come-nc
reviewed
Oct 15, 2026
Every operation of an Imaginary pipeline decodes and encodes its input, so autorotate ahead of fit did that at full resolution for every image, whatever its orientation. Fit first, into a square box of the larger side and keeping the EXIF orientation, then autorotate the small result, then fit to the requested box and strip the metadata. This covers what the EXIF check before it did only for JPEGs at orientation 1: every other format, and rotated images. HEIC no longer needs a case of its own, as the HEIF loader applies the image's rotation already. Measured against a 2500 MB container: a 200 MP JPEG peaks at about 200 MB instead of 715 MB, a 200 MP TIFF at about 1 GB instead of 2 GB, and a 761 MB TIFF no longer runs out of memory. A single fit without norotation is no alternative: fit swaps the box for EXIF orientations 5 to 8, and bimg rotates on top of that. Assisted-by: ClaudeCode:claude-opus-5-5 Signed-off-by: Martin Rüegg <martin.rueegg@metaworx.ch>
martin-rueegg
force-pushed
the
perf/imaginary-shrink-before-rotate
branch
from
October 15, 2026 12:29
9a0876b to
7af437b
Compare
This branch has not been deployed
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.
Summary
imaginary-powered preview generation is applying multiple operations on the full-sized image, where it can be handled more efficiently if - in a first step - the resize to the target scale is performed and other operations like rotation and cropping followed from there. Saves memory pressure and increases speed.
What changes
fitinto a square box of the larger side, without rotating and keeping EXIF →autorotate→fitto the requested box, stripping metadata.autorotate→smartcrop.Technical details
autorotatefirst is expensive: bimg's autorotate-only path decodes and re-encodes thewhole image whatever the orientation (
resizer.go:38-45). The 2022 premise, "almost instantwithout rotation", does not hold.
fit:Fitswaps the box for orientation > 4 (image.go:134-147, since 2018), and bimgrotates as well.
stored image, not the shown one. Measured: 2048 × 1536 where 2731 × 2048 fits.
Measurements
AIO Imaginary
sha256:0e32abf8…, 2500 MB memory limit, box 4096², quality 80.Peak anonymous memory:
Correctness: every result upright, sized as expected, and without EXIF:
heif-convert.Tests
ImaginaryTestcovers six image types, a non-square box, WebP output and the three convert types.Checklist
3. to review, feature component)stable32)AI (if applicable)