Faster Application Startup using Custom Profiles with Startup Tracing on Android
In our efforts to bring you extremely fast startup times on Android, we’re bringing you the ability to record your own profiles to use with startup tracing on Android.
What is a custom profile?
A custom profile is a profile that is generated based on running an embedded profiler against your application to find out which methods are JIT compiled during the startup. The custom profile can then be used in your release application to get your users into your app even faster.
To use custom profiles with startup tracing on Android, you’ll need Visual Studio 16.5+ or Visual Studio for Mac 8.5+.
Today, you can get started using custom profiles with startup tracing via the command line and MSBuild. In a future version of Visual Studio, you will be able to record custom profiles inside the IDE!
- Open a command prompt or terminal against your Android project’s directory that contains the
- Ensure only one Android device is attached.
- Under the app’s Android Manifest > Required permissions in the Visual Studio project property pages, ensure the INTERNET permission is enabled.
- Let your application run until it’s loaded.
- This will add a custom.aprof file to your project which you’ll want to change the
AndroidAotProfile. You can do this by adding the following
<ItemGroup> <AndroidAotProfile Include="$(MSBuildThisFileDirectory)custom.aprof" /> </ItemGroup>
- Finally, you’ll need to include two MSBuild properties to your
Releaseconfiguration to enable the feature and use the custom profile.
<PropertyGroup> <AndroidEnableProfiledAot>true</AndroidEnableProfiledAot> <AndroidUseDefaultAotProfile>false</AndroidUseDefaultAotProfile> </PropertyGroup>
Note: On Windows, you can use Developer Command Prompt for Visual Studio(Tools > Command Line > Developer Command Prompt). This is especially helpful for side by side installations of Visual Studio.
Differences in Startup Tracing Modes
You can see the differences in startup tracing modes against a larger Xamarin.Forms application. The measurements below were collected against the SmartHotel360 repository.
|Release||Release/AOT||Release/Startup Tracing (Default)||Release/Startup Tracing(Custom)|
Custom profiles has the most optimal startup performance with a minimal overhead to APK size!
For more details on profiling your applications using our embedded profiler, see our documentation.
Inspecting AOT Profiles
The AOT profiles generated by the profiler can be analyzed and/or filtered by the
To get started with this tool, run the
aprofutil tool with the
-s (summary) argument against your generated
aprofutil -s SmartHotel.Clients.Android/custom.aprof
Summary: Modules: 50 Types: 1,750 Methods: 7,940
For more information regarding using the
aprofutil tool, see the documentation.
Note: Because this tool uses
adb, you will want to ensure
adb is on your environment path. It can be found in your Android SDK’s android-sdk\platform-tools directory.
Now you can record and use custom profiles when using startup tracing on Android. This provides you the most optimal application startup time with a slight increase to APK size.
In the future, you will be able to record profiles within Visual Studio and Visual Studio for Mac.
We can’t wait to see how this feature improves your application’s startup times.
Also, don’t forget to check out Ryan Davis’s excellent blog article on Using Custom AOT Profiles with Xamarin.Android, where he goes through using this feature within his apps!
We’re continuously improving this experience and want to know your thoughts on it! For anything you believe is an issue with Startup Tracing with Android apps, please file an issue on Developer Community.
Additionally, let us know if you have any suggestions for how we can improve the Startup Tracing experience.