Repository navigation
Speed up decode_bounded on grid HEICs - #41
Merged
Merged
Conversation
Decode tiles through an ordered sliding window instead of batches that wait for their slowest tile, and copy unscaled tiles into the output a row at a time (or in 16-row blocks when rotated or mirrored) using precomputed strides.
# Conflicts: # src/bounded.rs # src/bounded/resample.rs
Author
|
@codex review |
This was referenced Nov 26, 2026
laurenspriem
added a commit
to ente/ente
that referenced
this pull request
Nov 26, 2026
Update `ente-image`'s HEIC decoder pin from `5fbe1d2` to [`5b0a6af`](ente/heic-decoder@5fbe1d2...5b0a6af). It brings: - Faster bounded decoding of grid HEICs (ente/heic-decoder#41). Measured there on a Pixel 10, `decode_bounded` took 0.62–0.77× as long as the regular decoder on 12–24 MP phone HEICs, against 1.14–1.29× before. This is the path ML indexing, face thumbnails, OCR and the internal Android HEIC viewer use. - `decode_bounded` now decodes HEICs with an odd-origin crop or an odd-sized rotation or mirror instead of refusing them (ente/heic-decoder#39). - The regular decoder now matches libheif on those crops, rotations and mirrors in HEIC and AVIF, converting chroma to 4:4:4 before the transform (ente/heic-decoder#37, #38, #40). A grid whose tiles need different conversions now fails, as it does in libheif. - AVIF items without a `colr` nclx property now use the AV1 stream's range and matrix (ente/heic-decoder#40). On 309 HEIC, HEIF and AVIF files (ente's test fixtures, phone HEICs, libheif's examples, fuzz and stress files, and heic-decoder's generated corpora), both decoders give the same pixels or the same refusal under both pins on 294, including every real phone photo. The other 15 are generated odd-crop and odd-size rotation and mirror files: the regular decoder now gives different pixels, and `decode_bounded` decodes them instead of refusing, with exactly the regular decoder's output. Source fork PR: laurens-pilot#308 @laurenspriem Co-authored-by: laurenspriem <laurens-pilot-git@lrns.me>
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.
On grid HEICs,
decode_boundedtook up to 1.29× as long as the regular decoder, although profiling showed it used only about 9% more CPU. It decoded tiles in batches and waited for the whole batch before starting the next one, so on phones with big and little cores every batch ran at the speed of its slowest tile. It also copied each tile into the output one pixel at a time on the calling thread.Tiles now go through an ordered sliding window: as soon as the oldest tile is placed, the next one is read and started, with the same number of tiles in flight and the same memory accounting. Unrotated tiles are copied a row at a time, and rotated or mirrored tiles pixel by pixel in blocks of 16 rows, using precomputed strides.
Bounded decode time as a multiple of the regular decoder on a Pixel 10 (USB), medians of 3 alternating rounds of 5 decodes:
On a Samsung M36, an earlier version of this PR with a less eager scheduler measured 0.77–0.96×, against 0.96–1.11× on main.
Output is unchanged. On 307 HEIC, HEIF and AVIF files, including the bounded oracle corpus, at a max side of 6000 and 97, every decode gave the same dimensions and pixel hash as main and every refusal the same error, with and without
parallel-gridand at budgets down to 40 MiB.Not measured on an iPhone or in the app.
Source fork PR: laurens-pilot#29
@laurenspriem