Page MenuHomePhabricator

Enhance Smart Image Cropping Performance
Closed, ResolvedPublic2 Estimated Story Points

Description

Description

This ticket is for tracking a follow-up patch that updates the existing smart image cropping functionality with refinements aimed at improving performance.

Acceptance Criteria

Crops continue to respect defined aspect ratios.
New cropping logic applies automatically
QA validation confirms results remain stable across a representative set of sample images.

Notes:

This enhancement builds on the current implementation. Please review for consistency and verify that it integrates cleanly with existing pipelines.

QA steps

  • test with network throttled to "slow 4G" setting to ensure that image download-to-display time is more reasonable (should be much shorter due to not waiting for a full-resolution image download)
  • test images of various aspect ratios to ensure they scale and crop as expected
    • very wide images are most likely to look different as they will be "stretched" much more than before

Requirement

Scope: Smart Image Cropping (desktop + mobile).

  • Updated cropping logic must improve performance while preserving correct aspect ratios.
  • Cropping results must remain stable across sample images.
  • Enhancement must integrate seamlessly with existing cropping pipeline.
  • On slow networks, image display must be faster since it should not wait for full-resolution image downloads.
  • Wide images must still crop and scale correctly (no broken aspect ratios).

BDD

Feature: Enhanced smart image cropping performance

  Scenario: Faster image load under poor network conditions
    Given I am on a slow network connection
    When an image is displayed with smart cropping enabled
    Then the image loads and displays quickly without waiting for full-resolution download
    And the crop respects the defined aspect ratio

  Scenario: Stable cropping results across images
    Given I have a set of sample images with varying aspect ratios
    When each image is displayed with smart cropping enabled
    Then the crop respects the defined aspect ratio
    And the subject remains centered consistently

  Scenario: Wide image handling
    Given I view a very wide panoramic image
    When it is displayed with smart cropping enabled
    Then the image scales and crops correctly
    And no broken or distorted aspect ratios occur

Test Steps

Test Case 1: Performance on throttled network

  1. Enable network throttling in DevTools (Slow 4G).
  2. Open a page with images using smart cropping.
  3. AC1: Images display quickly without waiting for full-resolution files.
  4. AC2: Cropping respects the defined aspect ratio.

Test Case 2: Stability across various aspect ratios

  1. Load sample images in portrait, landscape, and square aspect ratios.
  2. AC3: Each image respects its aspect ratio in the cropped result.
  3. AC4: Main subject remains centered.

Test Case 3: Wide image handling

  1. Load a very wide panoramic image.
  2. AC5: Image scales correctly to fit viewport.
  3. AC6: Cropping preserves correct aspect ratio without distortion.

QA Results - Patchdemo

Event Timeline

Change #1186624 had a related patch set uploaded (by Kimberly Sarabia; author: Matthias Mullie):

[mediawiki/extensions/ReaderExperiments@master] Optimize crop

https://gerrit.wikimedia.org/r/1186624

HSwan-WMF moved this task from Incoming/Inbox to Needs Refinement on the Reader Growth Team board.
ovasileva set the point value for this task to 2.Sep 15 2025, 4:59 PM
bvibber moved this task from Committed to Doing on the Reader Growth Team (Sprint 6) board.

Going to combine this with my refactoring for loading states for T402973 and submit a single patch covering both tasks.

Change #1188891 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/ReaderExperiments@master] WIP load states and optimization of detail view image

https://gerrit.wikimedia.org/r/1188891

Change #1190357 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/ReaderExperiments@master] Remove unnecessary high-resolution image download

https://gerrit.wikimedia.org/r/1190357

Change #1190772 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/ReaderExperiments@master] Precalculate average colors from thumbnails already loaded

https://gerrit.wikimedia.org/r/1190772

Ended up with two perf-related patches here:

https://gerrit.wikimedia.org/r/1190357
reimplements the initial fix for avoiding the extra download, differently. needs to be double-checked that it's using the right sizes

https://gerrit.wikimedia.org/r/1190772
additional performance fix avoiding extra load of thumbnail for background color calculation, by using the thumbnails we're already loading for the ui

Change #1190788 had a related patch set uploaded (by Bvibber; author: Bvibber):

[mediawiki/extensions/ReaderExperiments@master] WIP: Avoid reflows while loading thumbnails in VTOC

https://gerrit.wikimedia.org/r/1190788

Change #1190357 merged by jenkins-bot:

[mediawiki/extensions/ReaderExperiments@master] Remove unnecessary high-resolution image download

https://gerrit.wikimedia.org/r/1190357

Ok I split out the separate patches, this one's ready to close once QA's happy.

bvibber updated the task description. (Show Details)

Change #1190788 abandoned by Bvibber:

[mediawiki/extensions/ReaderExperiments@master] WIP: Avoid reflows while loading thumbnails in VTOC

Reason:

I accidentally broke my chain of change ids ;) new version at I9ddde43857a73bc621f4dd036b854ec45b1d6eaa

https://gerrit.wikimedia.org/r/1190788

Test wiki created on Patch demo by ETadros (WMF) using patch(es) linked to this task:
https://a5845d7842.catalyst.wmcloud.org/w/

Test wiki on Patch demo by ETadros (WMF) using patch(es) linked to this task was deleted:

https://a5845d7842.catalyst.wmcloud.org/w/

Test wiki created on Patch demo by ETadros (WMF) using patch(es) linked to this task:
https://0f263e113b.catalyst.wmcloud.org/w/

Test wiki on Patch demo by ETadros (WMF) using patch(es) linked to this task was deleted:

https://0f263e113b.catalyst.wmcloud.org/w/

Test wiki created on Patch demo by ETadros (WMF) using patch(es) linked to this task:
https://badfe63bcb.catalyst.wmcloud.org/w/

Test Result - Patchdemo

Status: ✅ PASS
Environment: patchdemo (https://badfe63bcb.catalyst.wmcloud.org/w/)
OS: macOS Sequoia 15.5
Browser: Chrome Canary (latest as of test date)
Device: MS
Emulated Device: NA

Test Case 1: Performance on throttled network

  1. Enable network throttling in DevTools (Slow 4G).
  2. Open a page with images using smart cropping.
  3. AC1: Images display quickly without waiting for full-resolution files.
  4. AC2: Cropping respects the defined aspect ratio.

screenshot 57.mov.gif (1,574×1,260 px, 843 KB)

Test Case 2: Stability across various aspect ratios

  1. Load sample images in portrait, landscape, and square aspect ratios.
  2. AC3: Each image respects its aspect ratio in the cropped result.
  3. AC4: Main subject remains centered.
screenshot 58.mov.gif (1,574×1,260 px, 1 MB)
screenshot 59.mov.gif (1,574×1,260 px, 1 MB)

Test Case 3: Wide image handling

  1. Load a very wide panoramic image.
  2. AC5: Image scales correctly to fit viewport.
  3. AC6: Cropping preserves correct aspect ratio without distortion.

See Test Case 2.

Change #1186624 abandoned by Matthias Mullie:

[mediawiki/extensions/ReaderExperiments@master] Optimize crop

Reason:

Superseded by a bunch of work by Brooke + Ife26a1c930c7cc41359f9eff00fd24e6138ff1fb

https://gerrit.wikimedia.org/r/1186624

Test wiki on Patch demo by ETadros (WMF) using patch(es) linked to this task was deleted:

https://badfe63bcb.catalyst.wmcloud.org/w/

Test wiki on Patch demo by ETadros (WMF) using patch(es) linked to this task was deleted:

https://badfe63bcb.catalyst.wmcloud.org/w/