Speed up initial loading
We're developing an app which is partially native and partially hybrid. We will open cordova activity when user clicks on an menu item and finish the activity when user clicks back. Problem with this approach is, it takes a while to render on the screen for first time. We are hosting all the resource files in the assets folder so caching doesn't make much sense. Is there any progressive way to load the application?
@danbucholtz I managed to solve the run time error myself, it was related to angular barrels. I had to reference the modules with complete path in the app.module.ts file. Don't know why it started failing with the newer script version though!!
However, after fixing the error and running ionic run android --prod --release on my Samsung Galaxy S4 Android Version 5.0.1 the initial load is still 7-8 seconds. There is No change in the initial at all after updating it to the latest ionic-app-scripts versions.
We really need to improve upon the inital load time. I personally don't think the phone and Android version I am using is relatively that old to have that much slow boot time. I would be happy somewhere between 3-4 seconds boot time on old-mid range phones.
@graphefruit, I did 2 steps not mentioned in the release procedure
- I manually modified package.json file to change script version to
0.0.47and then run npm install. - I also removed .tmp directory which is not valid with new build process as per the release notes.
Apart from this I just followed the release procedure.
Are you running the latest ionic cli? Can you verify? npm install -g ionic@latest.
Can you run npm run ionic:build --aot and verify that ngc is run in the terminal? When you run ionic run android --prod --release do you see ngc in the terminal?
Thanks, Dan
Hello @danbucholtz,
yes I see ngc when running--prod --release. Also I installed ionic@latest more then 4 times ;) via cmd without any errors - maybe we need to change some settings in the package.json - they weren't upgrade on their own. Also I've installed the nightly to maybe see some difference.
The other command I can try to run tomorrow morning.
Greetings Graphefruit
@danbucholtz
Yes, I am using the latest ionic-cli (Please see my workspace environment info at the end)
I also see the ngc in the terminal in both cases you mentioned please see screenshot for each of them
npm run ionic:build --aotionic run android --prod --release
1) Aot build

2) Production build while running on device

Still no difference in the initial load times for me which 7-8 seconds 😞 😞
cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.3
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.47
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 10
Node Version: v6.9.1
Xcode version: Not installed
@savanvadalia long loading time could be specific to your app. It would help if you try & provide numbers for a starter app or ionic-conference app so numbers are comparable.
Also it make sense to upgrade to ionic-angular RC4.
@danbucholtz Care, this post will be a bit longer:
My/Custom project
npm run ionic:build --aot

ionic run android --prod --release

ionic build android --prod --release

Still 10 seconds loading time.
Starter-App
@astec After you've asked, I've installed the starter app. And made the same here.
npm install -g ionic@latestionic start o5 --v2ionic info
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.0-rc.4
Ionic CLI Version: 2.1.17
Ionic App Lib Version: 2.1.7
Ionic App Scripts Version: 0.0.47
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 8.1
Node Version: v6.9.1
Xcode version: Not installed
-
ionic platform add android -
npm run ionic:build --aot
-
ionic run android --prod --release
-
Times: 7.1 Note 1 - Android 4.1 - The starter project took about 5 to 5.5seconds 7.2. Note 2 - Android 7.0 (CM14) - The starter project took about 5.5 to 6.5 seconds
Conference - App
So next try for I've downloaded the starter app: https://github.com/driftyco/ionic-conference-app
npm installionic info
-> Looks like this one is not on rc.4, cause of this 3. I changed the package.json like mentioned in changelog.
"dependencies": {
"@angular/common": "2.2.1",
"@angular/compiler": "2.2.1",
"@angular/compiler-cli": "2.2.1",
"@angular/core": "2.2.1",
"@angular/forms": "2.2.1",
"@angular/http": "2.2.1",
"@angular/platform-browser": "2.2.1",
"@angular/platform-browser-dynamic": "2.2.1",
"@angular/platform-server": "2.2.1",
"@ionic/storage": "1.1.6",
"ionic-angular": "2.0.0-rc.4",
"ionic-native": "2.2.11",
"ionicons": "3.0.0",
"rxjs": "5.0.0-beta.12",
"zone.js": "0.6.26"
},
"devDependencies": {
"@ionic/app-scripts": "0.0.47",
"typescript": "2.0.9"
}
- deleted
node_modules npm installionic info
ionic platform add androidnpm run ionic:build --aot
ionic run android --prod --release
ionic build android --prod --release
- Startup times 11.1 Note 1 - Android 4.1 - 7- 8s 11.2 Note 2 - Android 7 (CM 14) - 7 - 8.5 s
The time was measured by "click on app icon" till the screen appeared with content So even the conference-app with the latest release needs 7-8 seconds, so it isn't a custom-release project. Even so the conference-app is still realy small with no big internet activity, or html-5 filesystem.
Hope this helps. Greetings Graphefruit
@jgw96, can you weigh in on the above? Justin is our resident Android expert. My initial thought is those are really old (7 generation) old phones and that could play a factor, but I will defer to Justin.
Thanks, Dan
FWIW I have Sony Compact Z3, which is not really that old and the times are pretty much the same on Android 6.x.
@jgw96 @danbucholtz I've installed it now on my Google Pixel aswell - startup time of the conference app - took 3.5 to 4 seconds. Fun fact: I've had 10 times startup times to 8-10 seconds - then I removed and installed the app again, and the time went down to 3.5 to 4 seconds again.
@graphefruit yeah, but reinstalling can't be the right way. ;-) Interesting (profiling) would be, were so much time is spent on and how fast other (angular) frameworks (Ionic 1, OnsenUI etc.) start a simple "hello world" app on the very same device. Startup time of the RC4 conf app on my (not too old ) Moto G2 is about 6 sec :-/
@mpaland Thats true, it won't be the right way, but sometimes providing all information you found is the best way and hope ionic can use them. Like I mentioned in some posts earlier - I'm porting my Ionic1 app to Ionic2, there was a startup time from 3 to max 4 secs. The ported project takes 7-8 seconds on the same device.
HTC One M8 (Android 6.0 - Vanilla)
So after your suggestion I've installed an Ionic1 project:
ionic start myprojectionic platform add androidionic build android- Ionic1 - Startime on HTC One M8 (Android 6.0) was about 2.5 seconds.
- Ionic 2 - Conference App - Start time: 5 seconds
- Ionic 2- Starter App - Startime: 4 seconds
- Ionic 1 - My custom project: 4 seconds
- Ionic2 - My custom project: 7 sec.
Shock! - Ignore this sentence.
So even with the starter app in ionic 2 the difference is still about 1.5 seonds The HTC One M8 was released 2014 March
Moto G (Android 5.1)
So and here we go with an next device - Moto G - Android 5.1.
- Ionic1 - 4.5 to 5.5 sec sec
- Ionic 2- Conference app: 8.5 to 10.5 sec
- Ionic 2 - Starter app: 6 to 6.5 sec
- Ionic 1 - My custom project - 5.5 - 6 sec
- Ionic 2 - My custom project - 7-8 sec.
So as you see, we've still 1.5 sec difference, the conference app needed a lot more time The Moto G was released 2013 November
So I think that should answer all questions now.
And yes: Every project in ionic2 was compiled with RC4 and appscripts 0.0.47 - before anyone asks
Are you using the latest Ionic CLI? How big is your bundle? Can you compile it with just npm run ionic:build --aot and verify that platformBrowserDynamic is NOT in there? --aot should skip minification but still give you the AoT build.
Thanks, Dan
@danbucholtz I'll check it and give you update in 15 minutes... - Maybe I've made a mistakes, to much compiles in the last 2 hours for this post =/ sorry
Keep in mind that platformBrowserDynamic has to basically run ngc in the browser when the app starts. Ultimately whether you're doing AoT or not, you're still using .ngfactory.js` files in the browser. It takes about ~20 seconds in your previous posts. So 20 seconds of compiling in the browser + 5 seconds start-up = long time.
5 seconds is still really long. Something is not quite right there.
Thanks, Dan
@danbucholtz Hello again dan! I'm sorry. I've installed the latest scripts, but the npm run ionic:build --aot wasn't avaiable on my custom project. - I've already updated my post on top.
So I've created a new project now, compiled and signed, and now the startup time is back to 7 seconds.
I like to mention that all other checks - conference/starter app were all with the ionic:build --aot and I can verify that platformBrowserDynamic is NOT there.
I've extracted all ZIPS and had a look into main.js.
Sorry again.
@graphefruit great effort for producing such stats on variety of devices 👍 @danbucholtz @jgw96, how abt Ionic Team releases production version of ionic-conference-app on play store and we can download provide you some stats on initial load.
If our load times don't match then possibly we are doing something wrong with our build which i really doubt is the case.
@danbucholtz It's been like this since RC.0, I doubt that anyone has been able to get startup under 5 seconds on Android. Ionic 1 startup times are better than Ionic 2.
Could you please look into it and do some profiling? I know that you're first trying to make sure that we are using the correct procedure to build the app, but this issue hadn't moved much in the last months and when multiple users are reporting this it probably won't be caused by a bad usage of the build script. Five (and that's the best case scenario here) or more seconds to start is a show-stopper for pretty much any Android app.
My statistics: Sony Z3 Compact Android 6.0.1 - AOT/prod/minified build (2 MiB JS bundle) takes 6 seconds to start both with and without Crosswalk. On slower devices it takes much more time (10 and more seconds were reported by users that tested my app).
@danbucholtz Would you mind sharing your team's device testing setup with us? It's unclear why you're not experiencing the same startup delays that the rest of us seem to be.
Hey everyone, thank you so much for the detailed diagnostics and testing info. This is our #1 priority right now, and while some of us here aren't seeing some of the long load times, others are depending on the device/OS/etc. We're narrowing it down, any extra info you have is always welcome.
@mlynch While this is not the missing 5 seconds, it could, maybe, be some time worth saving
https://github.com/driftyco/ionic-storage/issues/54
I have a gut feeling that one of the ionic libraries (storage) is initialising twice..... (rather than once). I could be very wrong, but still, while hunting for startup performance gains, throwing this up for consideration, especially if there is a wider issue here