Video: Improved Android Startup Times with Startup Tracing | The Xamarin Show
>> Join me my best friend John where he tells us all about startup tracing to dramatically reduce the startup time of your app up to 60 percent. So tune in. [MUSIC]. Welcome back everyone to the Xamarin Show. I'm your host James Montemagno, and today I've a good friend and if I could say my best friend in the entire world John Douglas, all the way from beautiful Utah. How's it going John? >> Hi, it's going great James, thanks for asking.
>> Yeah, it's great to have you on, because you are here to talk about supercharging and reducing the app startup time in Android apps, is that correct? >> Absolutely, yes. So if I can give some feedback here, one of the biggest pain points that we had was startup times on Android. You'd be developing your forums app, maybe developing a regular Android app and once you hit that "Play" button and you start to deploy your application, it takes a long time, right? Could take up to three seconds. So we really wanted to tackle that problem head on, and what we have for you is a special surprise today. >> Yeah, because also I would think that, well, each of the different platforms go through different compilation steps, you could be using forms or you're using a bunch of different libraries, and your application grows. Additionally, like with Android it's not like iOS, where you just have standards sets of devices.
On Android a newer devices like my Pixel 2 XL, like batter smooth. But if I go back to my old devices from five years ago that so a lot of people have, that's where some of the issues because we're building apps for today's phones not 2-3 years ago. Is that kind of the issue that we're running into a bit? >> Absolutely, the Android ecosystem is so fragmented with different devices, different RAM, different storage, different capabilities. So really it depends on the phone but at the end of the day, we wanted to tackle this head on and make sure that we can apply something that will affect all devices. >> Ooh beautiful. So what do you have for us? Because I would love to trim down the startup size as much as humanly possible. >> Absolutely. So what we have is a feature that we're calling startup tracing, and what this is, is basically if you're familiar with Mono. There's a feature within Mono that allows you to use a built-in AOT profiler.
What that does is it generates an AOT profile for your application based off of what it believes should be optimized that startup time or loaded. >> Okay, is this different from just like when AOT and iOS or an Android application today, or is that the thing that we're talking about? >> Yeah. So that's a little bit different. >> Okay. >> It's still using the AOT compiler. However, it's doing a more subset of that respective profile. So what that means is like typical AOT, you'd have a very large file set because what's happening is it's generating a file on the side. So then you have kind of a bloated APK, buy you do reap the benefits of having a faster application has started up. However, with start-up tracing instead of having that bloated APK, we're only doing a subset. Because of that, we're only bloating the APK by maybe like one to five megabytes, but at the same time we're drastically improving the startup speed as well.
>> I see. That's awesome, because I know that when a AOT came out, it was really great for Android because I've been a AOT in my iOS applications forever, but then [inaudible] they trade off where it's like you're ahead of time compiling everything. So what you're saying, if I was to summarize, is it's sort of like we're taking a slice of the startup like what's necessary to start your application making that crazy super optimized with this little tiny AOT profile bit because we've traced, if you will the startup of your application and sort of like a startup optimizer that will help boot your application super-quick? >> Absolutely, that you got it right on the nail. >> So what do I have to do that to change like tons of code, like they're going to install bunch of different stuff, and like how do I test it one of the processes here? >> Yeah. So it's actually very simple. Underneath the hood, it uses an MSBuild property, we're going to actually go over that today. But before that, I want to show you just kind of a typical file new project where I can just boot my application and see how fast that is.
So what I'll do here is I'm just going to play this emulator that already have booted up. This is just a Xamarin.Forms shell template. So what we're going to do is we have a Xamarin. Forms shell template here with the emulator already booted, and this projects already been built for you. This does not include this new feature, so what we're going to do is deploy here and we'll see how fast it takes to boot. >> So this is just the standard on the box, but this is the file list view more than just "Hello World". >> Yeah. So this is just the regular shell template has a comes in with the items and you can kind of browse to them and the likes, but you might have noticed that took a few seconds to actually get to that main screen. >> Now see you down actually, you want to do it again first? >> Yeah, let's do that again.
So one, two, three, little bit longer than three or so. So what we can do is, we're going to add a MSBuild property, and this is going to be a checkbox in a future version of Visual Studio. But what we'll do is we'll unload this project really quick, we'll edit this project. Under our Release configuration, we're going to add a quick property. >> So why would it why is it under a lease like we're in debug right now? So when we're using this new startup tracing, why is it important to put it here in releases? I know there's like global settings, but here maybe talk about these property groups and why this ones here? >> Yeah, so the reason why we want to put this in release is, because this is going to be a public facing or this is going to be our app that our users are going to use. We don't necessarily need to do this every time that we're debugging and the likes, just because like we want to have the full environment and all the symbols and everything for development purposes.
However, for a release we really want to make sure that we have the most optimized build available so that our users can have the most performant and speedy application. >> Got you, that makes sense. >> Yeah. So again, it doesn't matter. I did have the debug configuration but we'll switch that to release, so this gets picked up. All I'm going to do is, I'm going to go go ahead and deploy this. >> All right, reload that puppy. >> Sorry? >> So you could've added that. So you unload it the project to editor, you could have also opened that maybe like in VS Code, for instance? >> Exactly, any text editor really just need to put that property in there. So now we're still under a release, and we're going to deploy that.
We have one more step just because we did switch it to release mode, we're going to need to switch to an X86 ADI. So just give it a second here. >> Oh yes, so File New and Android emulators that people don't know, they're X86 based. So you're going to obviously needed generate an X86 architecture there. That I liked that. I did tell you exactly what you needed to do which was actually quite nice. >> Yeah. We actually switch that. I error message recently. So it's nice and helpful for real. >> So now this is going to go through a full recompile, because you've never built it for a release. >> It sure will. >> Got you. So in this instance though, there's all these settings in maybe while it's building and kind of talk about all the different things that are going on here. Is this where the checkbox will live in the future? >> Yeah. So the checkbox will live under this code generation and runtime section over here, and of course, this is going to be available to all editions of Visual Studio.
So traditionally as an enterprise user you'd have access to AOT compilation, as a community user or above, you get access to use Startup Tracing. >> Oh very cool. >> Take a look at this, look how fast that loaded. Less than a second it seemed. So that's kind of start tracing in a nutshell really easy to get started. Of course, we're going to make it even easier for you with putting your checkbox in the future version, but, yeah, so that's kind of Startup Tracing. >> Do you want to show us one more time? I loved like sometimes you got to watch it again in action, right? >> Absolutely. So let's close out some of these applications we have in this emulator, and we'll just boot it up one more time and boom. >> Now, did you have a side-by-side of it, because it is nice to see them, did you have that video side-by-side? >> Absolutely.
So I do have a gift here, and we're going to minimize this emulator. But you might notice exactly what we kind of did here minus the naming is an older gift, but you might notice that normal is a little bit slower around three seconds whereas Startup Tracing is about a second. >> Yeah, and even when you did it from the ID, it's very noticeable and this is of course on an emulator which is probably going to have some reduced memory already. I think usually the emulator is like one gig of RAM and of course it's based on the power of your machine. So when you actually run this on even more beefier hardware, or even lower hardware, you're going to see these drastic changes basically, correct? >> Absolutely, yeah. >> Very cool. So this is like you said it's using a combination of AOT technology, we're tracing the startup of what's in your application, and then you just check a check box or in this instance we just put it into the CS plug, right? >> Yeah. So just some background there is, we actually provide you two default profiles out of the Git.
One of them for regular Android projects and one of them for Xamarin.Forms projects. So what we did is, basically, we looked through typical applications and found we use the profiling tool to then generate those profiles. So that's basically saying "Hey, as this type of application, this is how you're going to start up the fastest." So a little bit further on our roadmap, what we're going to be doing is we're going to be allowing you to create your own custom profile. What that means, is that, as a user and you have a complicated application say of a very complicated Xamarin.Forms application, a lot of things going down on startup, or at least initializing, you're going to want to be able to profile that and create your own profiles. Therefore, you'd be able to optimize your app to reap all the benefits that we see here today.
>> Very cool, that's awesome. So today [inaudible] Xamarin.Forms app or Xamarin Android app without forms doesn't matter, I can take advantage of it in the future. >> Yes. >> I can do crazy other optimizations on top of that, but John that is- >> Absolutely. >> -spectacular. >> Yeah. It's very cool stuff. >> I love when you can come on and demo something and it's one line of code, or one check box in the future you know what I mean? Like check out this thing but it's cool to get that background of how it actually is working. >> Yeah, exactly. We do have a blog coming out too, so check that out. >> Awesome. I'll put links to the blog, to the release notes because you can get this today, and of course the documentation so you can learn about all the packaging stuff that you need in your app. John, thank you so much for showing this off and thank you for being an awesome PM on the Xamarin Android team and help in getting these features out there and talking about them. >> Absolutely, thanks for having me James. >> Awesome. Well, thanks everyone for tuning in, and don't forget to subscribe wherever you're watching on Channel 9 or YouTube, and ding that bell to get notified so you get the latest Xamarin shows right in your inbox.
So until next time I'm James Montemagno. This is The Xamarin Show and thanks for watching. [MUSIC]. Hi, James here, just wanted to check in and thank you for watching this video. Now, do all the things that you know you want to do such as like, subscribe, and ding that notification bell to become part of the notification squad. While you're here, check out all these awesome videos that I've already recorded, click on that thing. Click it, watch it, do it..