Hypothesis:
Armv7a with thumb and -Os provides smallest binary.
Setup:
Build canvas_stress.py into an application. Each time, I use the same build script and same blacklist (somewhat custom) and different compiler options. Blacklist isn't totally tuned, so there is some data not reacting. See notes for findings that affected the results.
Results:
Oflag ARM version Thumb Bytes MB
-O2 -march=armv7 -mthumb: 5956509 bytes 5.9MB
-Os -march=armv7 -mthumb: 5610859 bytes 5.6MB
-Os -march=armv7 -marm: 5610618 bytes 5.6MB
-O2 -march=armv7a -marm: 5895994 bytes 5.8MB
-O2 -march=armv7a -mthumb: 5710331 bytes 5.7MB
-Os -march=armv7a -mthumb: 5342759 bytes 5.3MB (smallest test)
-O3 -march=armv7a -mthumb: 6130323 bytes 6.1MB (largest test)
Conclusion:
-Os seems to provide largest effect on size. Sure enough, compared to defaults we get a 10% reduction in apk size using -Os and mthumb with v7a. Not everything uses -Os and not all of the data is binary, so there is more effect on binary than just 10% and still more size reduction can be obtained.
Notes:
Theses tests revealed inconsistencies in our compiler flag support. Not all recipes work correctly, and while building I notice that many will list compiler options (Looking at you Python and PIL) such as -Os -mthumb -O3, which in fact overrides the build back to -O3, because the configure script doesn't react to the $OFLAG set in distribute.sh. I seem to have successfully modified the Python recipe to react to $OFLAG and am committing the change to github.
The blacklist still has the largest affect on the binary by far. The smallest file is one that doesn't exist. We could use some tools that do dependency tracking such as snakefood to dynamically create blacklists. We're using only about 20% of all the files built into APK right now?
To eliminate unused files, lazy loading is also very important. Import graphs don't help us if every module imports everything. I have customized my application.py to allow blacklisting the kivy/data/fonts directory. Customization was necessary because the file tries to import a lot of setting dependencies that I usually don't care about at all in production applications. The kivy/data/fonts directory makes us have about 1MB of data extra.
Thumb2 is noted to have better size/performance characteristics than Thumb1. What we probably want in the end is to select -Os for all of the dependencies such as PIL (always rarely used) and -O2 for a custom Cython file that might be part of the core of the application. There were not tests done on performance yet. I need a better benchmarking application to allow for real testing on the device. Canvas and layout animation tests are probably most needed. For applications needing raw speed, building Cython after the distribute step is still most important compared to tuning the compiler.