Skip to content

Bug 41500: Optimize for size on Android.

Merge Info

Issues

Resolves

Related

  • tor-browser-build#xxxxx
  • tor-browser#xxxxx
  • mullvad-browser#xxxxx

Merging

Target Branches

  • main: esr140-15.0
  • maint-14.5: esr128-14.5
  • maint-13.5: esr115-13.5

Backporting

Timeline

  • No Backport (preferred): patchset for the next major stable
  • Immediate: patchset needed as soon as possible
  • Next Minor Stable Release: patchset that needs to be verified in nightly before backport
  • Eventually: patchset that needs to be verified in alpha before backport

(Optional) Justification

  • Emergency security update: patchset fixes CVEs, 0-days, etc
  • Censorship event: patchset enables censorship circumvention
  • Critical bug-fix: patchset fixes a bug in core-functionality
  • Consistency: patchset which would make development easier if it were in both the alpha and release branches; developer tools, build system changes, etc
  • Sponsor required: patchset required for sponsor
  • Other: please explain

Issue Tracking

Uplifting

  • Patchset is a candidate for uplift to upstream projects (e.g. mingw, clang, etc)

Review

Request Reviewer

  • Request review from an applications developer depending on modified system:
    • NOTE: if the MR modifies multiple areas, please /request_review all the relevant reviewers
    • accessibility : henry
    • android : clairehurst, dan
    • build system : boklm
    • extensions : ma1
    • firefox internals (XUL/JS/XPCOM) : jwilde, ma1
    • fonts : pierov
    • frontend (implementation) : henry
    • frontend (review) : donuts, morgan
    • localization : henry, pierov
    • macOS : clairehurst, dan
    • nightly builds : boklm
    • rebases/release-prep : boklm, dan, ma1, morgan, pierov
    • security : jwilde, ma1
    • signing : boklm, morgan
    • updater : pierov
    • windows : jwilde, morgan
    • misc/other : morgan, pierov

Change Description

We're very tight on Android.

With the apks I built so far, we are slightly over the 100MB threshold with x86 apks.

A trivial flag we initially dismissed was to optimize binaries for size (-Os).

So, I added this flag to tor and its dependencies. I also added -ffunction-sections -fdata-sections, which should allow strip to remove more, but I don't think they're actually doing much.

Shall this not be enough, we can also try to remove some OpenSSL functionalities we don't use.

How Tested

I've only built, I haven't tried the binaries because it'd require a full Android build. I will do it at a certain point.

I built, then I extracted libTor.so from the output, and I compressed it:

rbm/rbm build tor --target alpha --target torbrowser-android-x86
tar -xf out/tor/tor-...-android-x86-....tar.zst
7z a -mx=9 .../tor.zip .../libTor.so

I compared the zip size before and after the change:

-rw-rw-r-- 1 piero piero 4071500 24 giu 09.30 tor-before.zip
-rw-rw-r-- 1 piero piero 3789643 24 giu 10.33 tor-after.zip

So, it's less than 300kB, but it should be good to allow us to release (hopefully).

At this point, even this small improvement is helpful.

I've also verified -Os is actually working on projects, by checking the tarballs' size before and after the changes.

-rw-r--r-- 1 piero piero  278565 24 giu 09.57 libevent-2.1.12-android-x86-cc81c2.tar.zst
-rw-r--r-- 1 piero piero  627229 12 giu 17.07 libevent-2.1.12-android-x86-800187.tar.zst

-rw-r--r-- 1 piero piero 11091939 24 giu 09.57 openssl-3.5.0-android-x86-b59be7.tar.zst
-rw-r--r-- 1 piero piero 11336141 12 giu 17.05 openssl-3.5.0-android-x86-42a0e8.tar.zst

-rw-r--r-- 1 piero piero  86084 24 giu 09.58 zlib-1.3.1-android-x86-12cf9d.tar.zst
-rw-r--r-- 1 piero piero  91862 12 giu 17.08 zlib-1.3.1-android-x86-1c3c17.tar.zst

-rw-r--r-- 1 piero piero 424881 24 giu 10.11 zstd-1.5.7-android-x86-795f14.tar.zst
-rw-r--r-- 1 piero piero 480363 12 giu 17.09 zstd-1.5.7-android-x86-01ef7e.tar.zst
Edited by Pier Angelo Vendrame

Merge request reports

Loading