Classes from the Fb App


Posted by the Google and Fb groups. Authored by Kateryna Semenova from the Google Android group and Tim Trueman, Steven Harris, Subramanian Ramaswamy from the Fb group.

Brown hand holding a stopwatch.


Enhancing app startup time just isn’t a trivial activity and requires a deep understanding of issues that have an effect on it. This yr, the Google Android group and the Fb app group have been working collectively on metrics and sharing approaches to enhance app startup. Google Android’s public documentation has a number of data on app startup optimization. Along with that we need to share the way it applies to the Fb app and what helped them to enhance app startup.

There at the moment are greater than 2.9 billion individuals utilizing Fb each month. Fb helps give individuals the facility to construct neighborhood and convey the world nearer collectively. It’s a place for individuals to share life’s moments, uncover and talk about what’s taking place, join and nurture relationships, and assist work collectively to construct financial alternative.

Fb app builders are dedicated to make sure that individuals have the absolute best expertise and that the app works seamlessly on each gadget, in any nation, and inside completely different community situations. Working collectively, the Google Android group and Fb group aligned on metrics definition for app startup and greatest practices and shared them on this article.

The place to begin

Begin by measuring your startup occasions. It will let you understand how good your person’s startup expertise is, observe any regressions, in addition to how a lot to take a position on bettering it. On the finish of the day, your startup occasions should be tied to person satisfaction or engagement or user-base development with a purpose to prioritize your investments.

Android defines two metrics to measure app startup occasions: Time-To-Full-Show (TTFD) and Time-To-Preliminary-Show (TTID). Whilst you can additional cut up it into chilly/heat startup occasions, this publish is not going to disambiguate between them – Fb’s method is to measure and optimize the startup time that’s skilled throughout all customers interacting with the app (a few of them can be chilly, some heat).


TTFD captures the time when your app has accomplished rendering and is prepared for person interplay and consumption, maybe together with content material from disk or the community. This will take some time on gradual networks and may rely upon what floor your customers land on. Thus, it might even be useful to indicate one thing straight away and let customers see progress continues to be taking place, which brings us to TTID…


TTID captures the time on your app to attract its background, navigation, any fast-loading native content material, placeholders for slower native content material or content material coming from the community. TTID ought to be when customers can navigate round and get to the place they need to go.

Don’t change an excessive amount of: One factor to be careful for is visually shifting your app’s content material between TTID and TTFD, like exhibiting cached content material then snapping it away as soon as community content material is available in. This may be jarring and irritating for customers, so make certain your TTID attracts sufficient significant content material to indicate customers as a lot as attainable of what to anticipate for TTFD.

Concentrate on person success

Your customers are coming to your app for content material that may take some time to load, and also you need to ship that content material to them as rapidly as you may.

Fb app builders give attention to a metric primarily based on Time To Full Show (TTFD), together with all content material and pictures, as a result of that represents the complete expertise of what customers got here to the app for. If a community name for content material or a picture takes a very long time or fails, builders need to know in order that they’ll enhance all the begin to end startup expertise.

What’s a superb goal for TTID and TTFD?

Fb’s startup metric is the share of app begins that they take into account “unhealthy,” which is any begin that both has a TTFD longer than 2.5 seconds OR any a part of startup that’s unsuccessful (e.g. a picture fails to load or the app crashes). Fb focuses on driving this share of unhealthy begins down both by bettering profitable begins that take longer than 2.5 seconds, or by fixing points inflicting unsuccessful begins. 2.5 seconds was chosen primarily based on analysis that confirmed this was significant to Fb customers (this additionally matches the Largest Contentful Paint (LCP) metric in the Net Vitals suggestions for internet sites).

Together with the complete expertise, particularly of any community calls to fetch latest content material, could make your TTFD startup metrics appear actually gradual in comparison with TTID. That is really a superb factor! It represents the true expertise individuals have together with your app. Enhancements you make to this may occasionally drive elevated utilization and notion of your app’s efficiency on your customers prefer it has at Fb.

Measuring TTFD may be tough relying in your app. If it’s too arduous, it’s high-quality to begin with Time To Preliminary Show (TTID). That will miss the efficiency of loading a few of your content material you probably have placeholders or pictures, nevertheless it’s good to begin someplace even when it’s only a subset of what your customers see interacting together with your app every single day.

Instrumenting TTID

In Android 4.4 (API degree 19) and better, logcat supplies a “Displayed” worth capturing the time elapsed between launching the method and the completion of drawing the primary body of the corresponding exercise on the display screen.

The reported log line appears just like the next instance:

ActivityManager: Displayed +3s534ms

Instrumenting TTFD

To instrument TTFD, name reportFullyDrawn() in your Exercise after all of your content material is on display screen. Make sure to embody any content material that replaces placeholders, in addition to any pictures you render (you’ll want to rely when the picture itself is displayed, not simply its placeholder). When you instrument calling reportFullyDrawn(), you may see it in logcat:

ActivityManager: Absolutely drawn {bundle}/.MainActivity: +1s54ms

Suggestions From Fb App Builders

Fb app builders have been optimizing the app for billions of customers throughout a mess of gadgets, platforms and international locations for a few years. This part shares among the key classes that Fb app builders utilized to optimize their app startup.

  • Perceive first, then optimize – When you’ve outlined a superb startup metric, instrumenting it in your app can can help you perceive and prioritize bettering your startup efficiency to ship a greater expertise on your customers. By beginning with instrumentation, you may show there is a chance, you may establish the place to focus your efforts, and you’ll see how a lot you’ve improved issues as you begin optimizing.
  • Repair crashes first – After you’ve instrumented your begins, make certain your app begins reliably. Crashes throughout startup are essentially the most irritating and quickest method to get customers to desert your app; measure and handle these first.
  • Don’t overlook about practical reliability – Additionally, don’t overlook about practical reliability: did your app present some content material rapidly, however fail to load all content material or take a very long time to load pictures? Your app could also be beginning quick, however failing to perform as a buyer desires (e.g., if tapping a button doesn’t work) – this worsens the client expertise.
  • Goal for consistency – Inconsistent efficiency is extra irritating than constant however slower than common startup efficiency. Check out the lengthy tail of your begins and see if there are any fixes or methods to mitigate these gradual begins. Don’t overlook to take a look at your offline and lossy community startup efficiency begins.
  • Parallelize work – Most trendy telephones have a minimum of 4 CPU cores, so there’s room to multitask! Don’t block the principle thread until you must. Transfer I/O and non-critical paths work off the principle thread.
  • Be lazy – When you’ve acquired a dependable and constant startup, have a look by all the pieces you’re doing to show your first seen display screen of content material—is there any work in there that’s not obligatory? Take away, delay, or transfer to the background any work that’s in a roundabout way associated to a startup expertise till after the app has began (however watch out to observe your app’s responsiveness as a counter-metric). Attempt to maintain your app’s onCreate() as light-weight as attainable. You may as well profit from utilizing the Jetpack App Startup library to initialize parts at utility startup. When doing so, make certain to nonetheless load all of the required modules for the beginning exercise, and don’t introduce sparkles the place the lazily-loaded modules develop into accessible.
  • Present progress, however don’t shift the UI an excessive amount of – Attempt to not shift what’s offered to customers round an excessive amount of throughout startup. It’s irritating to attempt to faucet on one thing, solely to have it change and do the fallacious factor. That is just like the Cumulative Format Shift (CLS) idea from net vitals. For network-based masses with indeterminate durations, dismiss the splash display screen and present placeholders for asynchronous loading. Contemplate making use of delicate animations to the content material space that mirror the loading state. Guarantee that the loaded content material construction matches the skeleton construction as carefully as attainable, to permit for a easy transition as soon as the content material is loaded.
  • Cache it – When a person opens your app for the primary time, you may present loading indicators for some UI components. The subsequent time a person involves your app, you may present this cached content material when you load newer content material. Ever seen your FB feed replace after your app is loaded as we fetch up to date content material from the community? Reducing community outing of your startup, when you can, is a good way to hurry issues up and introduce a extra constant startup efficiency expertise. Nevertheless, exhibiting cached content material could not all the time be one of the best method as the subsequent level suggests, and because of this you will need to measure what works higher for the client.
  • Go quick & gradual – Barely slower, contemporary & related content material could also be higher than quick stale content material. Exhibiting contemporary content material to your customers could also be extra precious than beginning up tremendous quick solely to refresh the content material quickly after startup. Consider whether or not it’s higher to optimize for exhibiting contemporary content material as rapidly as attainable with a timeout for exhibiting stale content material if the community is gradual, or to only present what’s accessible instantly if the community is offline.
  • Constant session begin floor – It’s possible you’ll discover it useful to reset customers to your foremost content material after your app is within the background for a very long time. Gadgets can maintain your app in reminiscence for a very long time.
  • Have a look at the interior workings – Hint and really have a look at what’s executing throughout startup or connect a debugger—you could be stunned what you discover! When you’ve acquired a superb understanding of the important path on your begins, you may effectively optimize your app’s efficiency. Spend money on your largest alternatives since you’ll know the place they’re.
  • Make it simple to do the fitting factor – Generally builders use unhealthy patterns and structure as a result of there are too some ways to do issues. Don’t be afraid to consolidate the patterns utilized in your app, and optimize them so it’s simple to select the way to full a activity and for that activity to be performant. instance of this may be keen code execution patterns. When you’re working code for content material that seems after the primary full display screen draw, you’re by definition hurting efficiency. Lazy code execution is an effective sample. Solely run code eagerly when it’s blocking the important path on your startup.

Suggestions From Google Android Staff

Google Android group’s suggestions to measure and optimize app startup can be found within the public docs: App startup time. This part summarizes among the key factors that ties into Fb’s suggestions above that each one Android app builders ought to take into account.

  • TTID and TTFD are essential metrics for app startup. Google Android ranks apps with TTID within the Play Console. TTFD is a super-set of TTID, so any enhancements in TTID ought to apply to each metrics.
  • Name reportFullyDrawn() to report TTFD and to let the system know that your exercise is completed rendering. To enhance app startup, the Android system adjusts optimizations to prioritize work that occurs earlier than reportFullyDrawn() is named. Calling this methodology when your app is in absolutely usable state will enhance your app startup time. Each utility ought to be utilizing this API! And don’t overlook to measure it.
  • Monitoring your app’s technical efficiency with Android vitals will make it easier to enhance your app startup. Utilizing the Play Console, you may view knowledge that will help you perceive and enhance your app’s startup time and extra.
  • We all know a bug in manufacturing is far more costly to repair in comparison with a repair at growth time. The identical applies to efficiency as properly. Setup your utility for measuring app startup early with native efficiency exams through the use of Jetpack Macrobenchmark: Startup.
  • Instrumenting is vital to understanding and optimizing startup as we’ve mentioned above. Android presents system tracing that may assist to dig deep and diagnose app startup issues.
  • The Jetpack App startup library supplies a simple, performant method to initialize parts at utility startup. Each library builders and app builders can use this library to streamline startup sequences and explicitly set the order of initialization. You need to use this library to set which parts load at what factors throughout startup.
  • A typical situation that impacts app startup is doing an excessive amount of throughout initialization – for instance, inflating giant or advanced layouts, blocking display screen drawing, loading and decoding bitmaps, rubbish assortment, and many others.


This text captures some key measures of startup and greatest practices to enhance startup expertise that helps drive person engagement and adoption for the Fb Android app. It additionally shares metrics, libraries and instruments really useful by the Google Android group. Any Android app stands to profit from making use of among the methods described within the doc. Measure and make your app startup pleasant and quick on your customers!