Skip to content

[MOL-21512][TIEN] refactor compression flow for image-upload - #682

Open
tientranngoc-alt wants to merge 2 commits into
mainfrom
MOL-21512
Open

[MOL-21512][TIEN] refactor compression flow for image-upload#682
tientranngoc-alt wants to merge 2 commits into
mainfrom
MOL-21512

Conversation

@tientranngoc-alt

@tientranngoc-alt tientranngoc-alt commented Jul 24, 2026

Copy link
Copy Markdown

Type of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing apis or functionality to change)
  • Documentation (change to documentation, comments or API descriptions)
  • Tests (improvements to unit tests or E2E tests)
  • Other (technical improvements, refactoring, or changes that don't fall into the above categories)

Description of changes

  • Link to ticket

  • Root cause: compressImage called convertBlob() 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) with convertHeicToBlob() (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 within maxSizeInKb.

Checklist

  • Changes follow the project guidelines in CONTRIBUTING.md
  • Looks good on mobile and tablet
  • Updated documentation
  • Added/updated unit tests

Screenshots

Screen.Recording.2026-07-24.at.14.13.36.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant