beeware / briefcase-android-gradle-template

A template for generating Android Gradle projects with Briefcase
MIT License
18 stars 19 forks source link

Cache all Python unpacking if app lastUpdateTime unchanged #19

Closed paulproteus closed 4 years ago

paulproteus commented 4 years ago

This speeds up the second time you start an app.

Before change app first start time: 2.9 sec

06-28 22:21:32.940 12868 12868 D MainActivity: onCreate() start
06-28 22:21:35.839 12868 12868 D MainActivity: onCreate() complete

Before change app second start time: 2.9 sec

06-28 22:22:15.250 12894 12894 D MainActivity: onCreate() start
06-28 22:22:18.214 12894 12894 D MainActivity: onCreate() complete

After change app first start time: 3.1 sec

06-28 22:19:32.755 12794 12794 D MainActivity: onCreate() start
06-28 22:19:35.879 12794 12794 D MainActivity: onCreate() complete

After change app second start time: 1.9 sec

06-28 22:20:18.820 12823 12823 D MainActivity: onCreate() start
06-28 22:20:20.889 12823 12823 D MainActivity: onCreate() complete

App first start time is the time between "onCreate() start" and "onCreate() complete" being logged when executing the app via rm -rf android && briefcase update android -rd && briefcase build android && briefcase run android -d @beePhone.

App second start time is the time between "onCreate() start" and "onCreate() complete" when I quit the app from the Android UI and then click the app icon from the launcher.

I have checked that "onCreate() start" is logged seemingly as soon as I click the app icon and that "onCreate() complete" is logged when the app shows its UI.

Note that even though it looks like this slows down the first launch, I think that was a fluke. The next time I tested it I got 2.8 seconds. This is pretty noisy, I'm afraid.

The use of lastUpdateTime scared me at first -- I wanted to use some deterministic APK hash or something. It's the system time at time of APK installation. I think it's completely OK to use it this way. Note that briefcase run currently always reinstalls the APK, even if that's not necessary, which means that for people developing an app, they'll never get to experience the speedy start behavior unless they click on the app from their Android device's launcher.

paulproteus commented 4 years ago

My preference here is that we do it the way I have it :) but if you want the changes you suggested, I'm happy to make them my time tomorrow, or have you make them before that and beat me to it. Just trying to pass the baton if possible in the interest of latency-reduction.