Convert non-transparent image resources from png to webp for 14kb APK size reduction

RESOLVED FIXED in Firefox 52

Status

()

Firefox for Android
Build Config & IDE Support
P1
normal
RESOLVED FIXED
a year ago
a year ago

People

(Reporter: ahunt, Assigned: ahunt)

Tracking

(Blocks: 1 bug)

Trunk
Firefox 52
Points:
---

Firefox Tracking Flags

(firefox52 fixed)

Details

(Whiteboard: [MobileAS])

MozReview Requests

()

Submitter Diff Changes Open Issues Last Updated
Loading...
Error loading review requests:

Attachments

(1 attachment)

(Assignee)

Description

a year ago
webp images are reported to be approximately 25% smaller on average than an optimised png [1]

Android supports webp for resource files from 4.0 (although it seems lossless images, and image with transparency, are only available on Android 4.2.1+ - this still needs to be investigated) - [2].

We currently support Fennec on Android 4.0.3+, so depending on the impacts of lossless/transparent image support we may or may not be able to convert to webp images.

Converting all our own resources to webp resulted in a 200kb apk size reduction. Also converting bundled support library resources resulted in a further 200kb saving, but that might not be viable for landing (doing this requires hacking webp conversion into our mach builds, however I do not know if it's possible to add a similar conversion in gradle builds).

Both of those experimental builds run without issues on a 4.4.4 device, I'm yet to test on 4.0.3.

We are also currently investigating using VectorDrawables in place of png/webp, however we won't be able to use VectorDrawable's in all situations (they also aren't recommended for images larger than 200dp x 200 dp), so we should still investigate webp support, and ideally enforce the use of webp in place of png.

[1] https://developers.google.com/speed/webp/docs/webp_lossless_alpha_study
[2] https://developer.android.com/guide/appendix/media-formats.html
(Assignee)

Comment 1

a year ago
Note: the following two image resources can't be converted if we convert just our own resources to webp. Both of these images seem to be intended to override support library resources, however I have a suspicion that the support library resources would actually override these - in which case we should either remove our own copies, or ensure that our own copies override the bundled version:
ic_media_play.png
ic_media_pause.png

We provide our own copies in:
/mobile/android/base/resources/drawable-hdpi/
/mobile/android/base/resources/drawable-xhdpi/
/mobile/android/base/resources/drawable-xxhdpi/

The mediarouter support library bundles its own copies, which would seem to override the Fennec copies, since they add the -v4 qualifier:
./OBJDIR/dist/exploded-aar/mediarouter-v7-23.4.0/res/drawable-hdpi-v4/
./OBJDIR/dist/exploded-aar/mediarouter-v7-23.4.0/res/drawable-mdpi-v4/
./OBJDIR/dist/exploded-aar/mediarouter-v7-23.4.0/res/drawable-xhdpi-v4/
./OBJDIR/dist/exploded-aar/mediarouter-v7-23.4.0/res/drawable-xxhdpi-v4/
Assignee: nobody → ahunt
Whiteboard: [MobileAS]
Blocks: 942609
(In reply to Andrzej Hunt :ahunt from comment #1)
> Note: the following two image resources can't be converted if we convert
> just our own resources to webp. Both of these images seem to be intended to
> override support library resources, however I have a suspicion that the
> support library resources would actually override these - in which case we
> should either remove our own copies, or ensure that our own copies override
> the bundled version:
> ic_media_play.png
> ic_media_pause.png

I added those two for our media notification. If they use the same names than icons in the support library then this isn't intentional. We can rename them. :)
(Assignee)

Comment 3

a year ago
9-patch images don't seem to be supported for conversion either:
https://code.google.com/p/android/issues/detail?id=201704

In a local gradle build I get:
mobile/android/base/resources/drawable-hdpi/color_picker_row_bg.9.webp: Error: '.' is not a valid file-based resource name character: File-based resource names must contain only lowercase a-z, 0-9, or underscore

(mach build's didn't complain about this, so I don't know if this is an artificial gradle limit, or whether android would also fail to load such images)
(Assignee)

Comment 4

a year ago
Trying to run the webp apk on a 4.0.3 emulator results in a startup crash while inflating some part of the layout, so it seems that the lack of transparency support is going to be an issue.

Looks like this will need to wait until our baseline is 4.2.1 / API 17, or possibly even API 18 just to be safe (4.2.0 doesn't appear to be supported, so we might need to miss the whole API 17 series to be safe).
Assignee: ahunt → nobody
Summary: Convert image resources from png to webp for 200kb APK reduction → Convert image resources from png to webp for 200kb APK reduction once we upgrade to API 17 / 4.2.1 baseline
Whiteboard: [MobileAS]
Comment hidden (mozreview-request)
Android 4.0.3, 4.0.4, 4.1, and 4.2 make up nearly 17% of our install base.

I'd be inclined to do some time-boxed testing to see if webp works at all, anywhere, on < 4.2.1 -- perhaps non-transparent images (first-run tour?).

If not, then WONTFIX this for now, because I would speculate it will be a year until we raise our minimum Android version requirement.
(Assignee)

Comment 7

a year ago
Turns out we only had a total of 6 definitely non-transparent pngs:

find . -name *.png -exec bash -c 'if ! `identify -format "%A" {}`; then echo {};fi' \;
./res/drawable-hdpi-v4/helper_readerview_bookmark.png
./res/drawable-hdpi-v4/notification_media.png
./res/drawable-xhdpi-v4/helper_readerview_bookmark.png
./res/drawable-xhdpi-v4/notification_media.png
./res/drawable-xxhdpi-v4/helper_readerview_bookmark.png
./res/drawable-xxhdpi-v4/notification_media.png

Converting just the non-transparent images appears to work on a 4.0.3 emulator without visible issues, so I'll try to land at least that.

The first-run images (which I believe are the largest images that we bundle) contain a transparent background which precludes us from doing a simple conversion, but I've filed Bug 1314328 to look at those.

While I'm at it, here's my conversion script - I wonder if a derivative thereof should be added to checkstyle?
find . -name *.png -exec bash -c 'if ! `identify -format "%A" {}`; then x={}; cwebp {} -o ${x%.png}.webp; rm {};fi' \;
Assignee: nobody → ahunt
Status: NEW → ASSIGNED
Iteration: --- → 1.8
Priority: -- → P1
Whiteboard: [MobileAS]
Comment hidden (mozreview-request)
(Assignee)

Updated

a year ago
Summary: Convert image resources from png to webp for 200kb APK reduction once we upgrade to API 17 / 4.2.1 baseline → Convert non-transparent image resources from png to webp for 14kb APK size reduction

Comment 9

a year ago
mozreview-review
Comment on attachment 8805918 [details]
Bug 1313990 - Convert non-transparent png to webp for APK size reduction

https://reviewboard.mozilla.org/r/89526/#review89664
Attachment #8805918 - Flags: review?(s.kaspari) → review+

Comment 10

a year ago
Pushed by ahunt@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/86966ebee065
Convert non-transparent png to webp for APK size reduction r=sebastian

Comment 11

a year ago
bugherder
https://hg.mozilla.org/mozilla-central/rev/86966ebee065
Status: ASSIGNED → RESOLVED
Last Resolved: a year ago
status-firefox52: affected → fixed
Resolution: --- → FIXED
Target Milestone: --- → Firefox 52
You need to log in before you can comment on or make changes to this bug.