ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Speed up initial loading

Open TheMohanraj opened this issue 10 years ago • 159 comments

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?

TheMohanraj avatar Jun 06 '16 07:06 TheMohanraj

@astec really? hope you are not in our position. This issue is preventing us from going live. Are you in this position? If you read my comment carefully. I asked Ionic team that, Can they able to release AoT patch (danbucholtz said it was done in separate branch) as quick release instead of AoT patch + other non priority bug fixes. If this is not priority for you and our comments were spamming you, I suggest go for unsubscribe.

TheMohanraj avatar Aug 10 '16 09:08 TheMohanraj

@dheran, I was in your position at some early beta thinking it's almost there and my app is almost ready to be released. But I got tired fighting with API/behavior changes. Since that time Parse.com announced they are shutting down and I have to rewrite my auth system. So I decided to put it aside and switched to developing a Telegram+FB bot for my app. I feel sympathy for your situation but this is what you get when you jump on a beta wagon. If you want guaranteed timeline your was free to choose Ionic1 or any other non-beta platform. I myself will be back to developing Ionic2 app once we get 1st release candidate. Or at least Beta12. Either I overestimate complexity of the "ahead of time compiling" or you underestimate it. Anyway I'm not going to teach anyone patience anymore here - please accept my apologies and good luck with your endeavour.

trakhimenok avatar Aug 10 '16 10:08 trakhimenok

This isn't the thread about posting your needs and experiences. Please stick to the topic or leave it as-is. 👍

Looking forward to ionic2 beta12. All the best team :)

lordgreg avatar Aug 10 '16 11:08 lordgreg

Hey @dheran! Im sorry and definitely feel your frustration, we've been working as hard as we can to get this working and i can happily say that we are extremely close now and it will be in the beta.12 release along with a few other critical bug fixes. We would have liked to have this out earlier but we have been working with angular for the past few weeks to fix some bugs on their end that was causing aot compile to not work. It has also taken some time for us to first, optimize Ionic for the new aot compile, and second, to make all the changes necessary to work with Angular 2 RC5. The reason we cannot recommend that you use the branch that dan mentioned above is because the gulp tasks to actually build your app are not completely done yet. So while technically you could use it you would not actually be able to build your app. We've been working with a pre-release version of Angular 2 rc5 for a while now, but we have to wait for that release to go public just like everyone else before we feel comfortable doing a release that includes it. We are still in beta, which means that things are being worked on and will change and that is just the name of the game when it comes to beta software. Finally, when interacting with others in the community would you mind keeping our code of conduct in mind? Thanks for using Ionic! Also, if you ever want to see what were working on you can check out our meeting notes (which also get shared on twitter) and our roadmap.

jgw96 avatar Aug 10 '16 14:08 jgw96

I'm not sure, but maybe the main progress in speeding up ionic are doing in the ngmodule branch. Am I wrong?

msaelices avatar Aug 19 '16 20:08 msaelices

Good spot @msaelices ! Actually, most of the framework side of this is being done here https://github.com/driftyco/ionic/commits/deeplinks-ngmodule at the moment. Thanks!

jgw96 avatar Aug 19 '16 20:08 jgw96

For me the problem is not about the initial loading (as while bootstraping), but every time the user went to a page he hasn't visited.

While waiting for this AoT compiler to come to ionic, what I did is add a splash screen (just a ionic page with the app logo on it) called TemplatePrecompiler that takes all the components (any @Component of my app, no matter if it's a Ionic page or a Component) and compiles them one by one on runtime. Once that's done, I forward to the home page. That's really useful, because the user just sees a splashscreen that takes a while (~5 seconds for my app) but once it's all loaded all the screens go fast. And you can even put a progress bar on that splashscreen.

I created a gist in here: https://gist.github.com/voliva/eb0242743661000896054601af72d1fd

voliva avatar Aug 31 '16 15:08 voliva

Just to give everyone an update, we're actively working on this. It has been a larger effort than we anticipated but we are moving forward and getting closer. We have a branch that is almost two hundred commits ahead of master that has all of the changes needed for AoT 😄

This will be coming soon. We are to the point where we are starting to test this internally. We aren't ready for public testing yet. This is our highest priority item and the entire framework team is working hard on this effort to get it right. No timeline as of yet, but I can say we're getting there and I'll continue to update this thread with new info as we have it.

Thanks, Dan

danbucholtz avatar Aug 31 '16 15:08 danbucholtz

+1

and my app.bundle.js is 3.8MB, to big...

wilhantian avatar Sep 09 '16 09:09 wilhantian

+1 What time release beta12?@danbucholtz

gisinaction avatar Sep 12 '16 01:09 gisinaction

with regards to @prijindal 's approach of putting the templates into the Component, will this be the same optimization level expected from the offline compilation? I tried this approach, it saves the time of the HTTP requests to fetch the template, but there is still a lag at first view load. I suppose this happens because angular compiles the custom html of the templates at the first view load.

I am quite new to angular and I would appreciate if someone can clarify this to me.

zerocode000 avatar Sep 12 '16 04:09 zerocode000

@moatazelgamal,

AoT compiling will result in a significant speed-up. It takes several seconds to run the compiler for a typical app ahead-of-time, so this is time shaved off from runtime. It's hard to say how much faster it will be for a typical app. We've only tested it on a very basic sample and the start-up time went from ~3 seconds to ~300ms. We have not done enough testing to know what sort of numbers a typical app will see, but it will most certainly be faster.

The changes for AoT are in place for the framework (we think... so far so good 😄 ) and now we're shifting over to making the build process A) simple, B) scalable and C) as fast as possible. The team and I are working on it together in this repo.

Expect to hear more soon.

Thanks, Dan

danbucholtz avatar Sep 12 '16 05:09 danbucholtz

@moatazelgamal my approach is not offline compilation, it is simply inlining templates. Offline compilation is going to make the initial loading a lot faster.

prijindal avatar Sep 12 '16 12:09 prijindal

All,

We are heavily testing this internally now. We've made some great strides this week.

Thanks, Dan

danbucholtz avatar Sep 16 '16 19:09 danbucholtz

Hello there, I see Ionic2 RC0 was released, Is this the expected beta12? The changelog of RC0 did not mention anything about AOT compiling. I think this feature is too good to be missed in the changelog :)

zerocode000 avatar Sep 28 '16 14:09 zerocode000

It was "released". We're still filling in the gaps right now 😄 with changelog, etc. Expect official details later today. We ran into technical difficulties yesterday so we're a little bit behind.

Thanks, Dan

danbucholtz avatar Sep 28 '16 14:09 danbucholtz

Hi Ionic Team! Thanks for your hard work!

gisinaction avatar Sep 29 '16 01:09 gisinaction

So excited about this. Can't stop tweeting since I first read about it. Kudos ionic team.

On Thu, Sep 29, 2016, 04:19 gisinaction [email protected] wrote:

Hi Ionic Team! Thanks for your hard work!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/driftyco/ionic/issues/6776#issuecomment-250346182, or mute the thread https://github.com/notifications/unsubscribe-auth/AAxEjznTYrcKZKFD2rElIqKkWrGIvvUrks5quxIvgaJpZM4Iuokt .

masimplo avatar Sep 29 '16 04:09 masimplo

First of all, thank you for this great progress! I have been testing the new version and the initial loading now feels faster.

I have also been testing it in a low-spec Android 4.4.4 to better feel the performance difference and comparing it to Ionic 1. With Ionic 2-rc0, I find these approximate results:

Project Cold boot Hot boot
ionic1-tabs 4,5 s 3 s
ionic2-tabs 5 s 3,5 s
ionic1-sidemenu 5 s 3,5 s
ionic2-sidemenu 5 s 3,5 s
clock (native app) 1 s <1 s
  • Projects created with these commands:
ionic start myTabs1 tabs
ionic start myTabs2 tabs --v2
ionic start mySidemenu1 sidemenu
ionic start mySidemenu2 sidemenu --v2

Although the projects are not the exact same implementations, they give us a starting point for comparison.

Even with ionic 2-rc0, the basic projects require around 5 secs to load up on cold, and around 3,5 secs when it had already been loaded previously. These are roughly the same times that I find with Ionic 1 versions. The blog post that introduces Ionic2 RC0 contains an animated gif showing the current load up time. Around 3 seconds.

Do we know where are the remaining seconds spent? (eg. Starting up the Javascript engine/webview, Cordova plugins, Angular 2 loading, ...)?

Can these seconds be optimized to have an experience closer to native apps?

SynerG avatar Oct 01 '16 11:10 SynerG

@SynerG, great info. I am a little swamped with some other stuff right now but we will have more feedback soon. Thanks for putting that together!

Thanks, Dan

danbucholtz avatar Oct 03 '16 19:10 danbucholtz