Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25240] Android: Improve incremental build times

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2020-02-01T01:55:40.000+0000
Affected Version/sRelease 6.2.0
Fix Version/sRelease 9.0.0
ComponentsAndroid
Labelsandroid, build, performance
ReporterJan Vennemann
AssigneeJoshua Quick
Created2017-09-06T21:32:11.000+0000
Updated2020-02-01T01:55:43.000+0000

Description

While working on TIMOB-24829 i noticed a few more things in the android build that can be improved, resulting in a faster build time on incremental builds. Compared to the iOS build, which only takes ~5s for incremental builds, the Android build is much slower with ~30-40 sek. Most of the time is spend on recompiling and dexer operations, which are unnecessary if nothing related changed. The Android builder already contains a lot of comments about what can be skipped or cached, but contains no actual code that would do that. The actions in particular are: - Compile java classes (only needs to be done when files in build/android/src or build/android/gen change - Run Proguard (only needs to be done when any java classes changed) - Run dexer (only needs to be done if any libraries changed, any files in build/android/bin/classes have changed or debugging/profiling was toggled. This alone will cut down the android build time by approximately one third. \\ ---- *Final Result:* Below are the performance improvements between Titanium 8.3.0 and 9.0.0 with [kitchensink-v2](https://github.com/appcelerator/kitchensink-v2) on a 15" MacBook Pro 2015 with a solid state drive.
Non-encrypted emulator builds:
- Clean Build: 52s -> 20s  (2.6x faster)
- Incremental: 18s -> 7s   (2.6x faster)

Encrypted device/production builds:
- Clean Build: 53s -> 21s  (2.5x faster)
- Incremental: 50s -> 14s  (3.6x faster)

Notes:
- Benchmarks exclude gradle daemon startup of ~5s which is a one time hit.
- Titanium did not support encrypted incremental builds before. This is new.

Comments

  1. Brian Knorr 2017-11-20

    Here is a trace log of our Android build taking ~4 minutes to run. https://gist.github.com/btknorr/f92cec0d658b6985c2e8151d07230ac1
  2. Josh Lambert 2018-04-12

    I've seen the issues on this ticket also -- especially the Dexer step. Localytics JAR from this module is a big offender: https://github.com/centrevilletech/localytics-hyperloop
  3. Michael Gangolf 2018-10-12

    Was digging around in the _build.js and I found that this line:
       if (!this.forceRebuild && fs.existsSync(this.buildBinClassesDex)) {
       		return next();
       }
       
    to skip the dexer. But it is never called in my tests since forceRebuild is true for different reasons: {noformat} Forcing rebuild: JavaScript encryption flag changed Was: undefined Now: false {noformat} or {noformat} Forcing rebuild: /test_alloy/build/android/build-manifest.json does not exist {noformat} Still when I just call next() instead of checking it (2nd compiler run) the app compiles fine and I get a running APK with changes to XML/JS files. Speed improvement was about 20sec! Would be nice to fix that.
  4. Lokesh Choudhary 2019-12-20

    FR Passed. PR Merged.
  5. Samir Mohammed 2020-01-10

    Closing ticket, Improvement verified in SDK Version 9.0.0.v20200109153329. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/11339

JSON Source