Slide icon indicating copy to clipboard operation
Slide copied to clipboard

Inefficient implementation of image displaying that would affect Slide’s runtime performance

Open struggggle opened this issue 4 years ago • 0 comments

Slide version: 6.6.1 Android version: Nexus 6 API 28

Hi,

I hooked the statements that perform image decoding in Slide and executed the app and found four defects that may affect Slide's runtime performance.

Defect 1:

When I opened the below page and swiped up, I found that the same 1460 * 1460 image was repeatedly created. The page is:

image

The repeated created 1460 * 1460 image is:

image

The created images I obtained by hooking Slide (“1460,1460" is the width and hight of an image) are:

image

The code responsible for decoding and creating the same 1460 * 1460 image is:

image

Code location: https://github.com/ccrama/Slide/blob/master/app/src/main/java/me/ccrama/redditslide/SubmissionCache.java#L437

After checking the source code, I found that there is no image cache for the repeated created images.

Because repeated decoding for creating a big image will take a lot of unnecessary time, adding the repeated created image to an image cache may be a good way to avoid these unnecessary resource overhead.

Defect 2:

From the above page that shows the image, we can find that the displayed image in the page is very small.

image

However, the created image is 1460 * 1460, which is so large.

image

If we downsample the decoded image to create a small image, we can also reduce unnecessary time consumption for image decoding.

Defect 3 & 4:

When I installed Slide and opened the page below:

image

I found that a 1792*1792 image was created, the image is:

image

After checking the source code for creating the image, I found that the image decoding process is executed on the UI thread.

image

Code location: https://github.com/ccrama/Slide/blob/master/app/src/main/java/me/ccrama/redditslide/Activities/BaseActivity.java#L499

However, it is not recommended by Android and we can move the process to a background thread. https://stuff.mit.edu/afs/sipb/project/android/docs/training/displaying-bitmaps/process-bitmap.html

What’s more, the widget that displays the image is 350*490, the created 1792*1792 image is too large for the widget used to display it. So, we can also downsample the image to a suitable size.

Hoping what I found can help to improve Slide's runtime performance.

Thanks.

struggggle avatar Mar 25 '21 14:03 struggggle