[MOL-21512][TIEN] refactor compression flow for image-upload - #682
Open
tientranngoc-alt wants to merge 2 commits into
Open
[MOL-21512][TIEN] refactor compression flow for image-upload#682tientranngoc-alt wants to merge 2 commits into
tientranngoc-alt wants to merge 2 commits into
Conversation
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.
Type of changes
Description of changes
Link to ticket
Root cause:
compressImagecalledconvertBlob()which decoded and re-encoded the image at full resolution(e.g. 2634×4680) before resizing => wasting 2–4 seconds per upload on a redundant encode cycle.
Fix
eliminate redundant full-res re-encode: Replace
convertBlob()(decode + full-res encode) withconvertHeicToBlob()(HEIC conversion only) +blobToImage()(decode once). The image is drawn directly onto a resized canvas, skipping the wasteful intermediate step.binary search compression with canvas reuse: Replace the old linear quality-reduction loop (up to 10 decode/encode iterations) with a binary search algorithm (4–6 encode-only iterations). The pre-drawn canvas is passed directly to
compressToTargetSize(), eliminating repeated decoding.early exit: Skip
compressToTargetSize()entirely if the resized blob already fits withinmaxSizeInKb.Checklist
Screenshots
Screen.Recording.2026-07-24.at.14.13.36.mov