How Google made their Android app start faster
Android Developers
0:00 Hi, everyone.
0:01 I'm here to talk about a user
0:03 centric redesign of Android Google Apps initialization,
0:06 otherwise known as how we made our app startup faster.
0:10 My name is Rivka strelnikov and I am
0:12 a software engineer on the Android Google Apps performance team.
0:16 I am hoping that this talk will help
0:18 with reducing app start up latency for your apps.
0:21 So it might be useful to first go through how our app starts and is used.
0:26 Let's start by going through a typical user search journey.
0:30 First you click on the Quick Search box widget,
0:33 then start typing and select a suggestions result.
0:38 You'll end up on the SERP, otherwise known as the search results page.
0:43 If you click on a link like that one there, you'll go to the web page.
0:47 However, this isn't actually in Chrome,
0:49 but in something called Chrome Custom Tabs.
0:53 Since we'll be focusing on ending up on that SERP, let's define a few terms.
0:58 This is the activity fragment boxed in yellow.
1:01 In Android activity takes care of creating a window in which we place our UI.
1:06 The content from our app and this takes up most of the screen.
1:11 The part of the screen in the red box is a web fragment.
1:14 This is a very important part of our app.
1:16 This is where the search results are displayed.
1:19 And now let's go through a short story.
1:22 In late 2024, which is now over a year ago,
1:26 we were looking into possible search latency improvements,
1:29 and we noticed that we were initializing this very important web
1:33 fragment at the point at which we were submitting a search query.
1:38 And this sparked some concern.
1:40 This seemed awfully late for initializing something so critical.
1:44 And so I ran a study trying to move it into earlier points in the code path,
1:49 and one was especially exciting looking.
1:52 Our launch experiment showed that we'd be saving
1:54 a very considerable amount on search latency with this change.
1:59 However, we couldn't launch it after a whole lot of time spent looking
2:04 at various slices and trying and seeing if we could salvage any entry point,
2:09 we came to the conclusion that we really couldn't.
2:13 The startup interactive latency shot way up by five
2:17 times the amount we'd saved on search latency.
2:20 And just to clarify, this is how long it takes to go from clicking to start
2:25 the app to when a user can actually start interacting with it.
2:30 And in addition, there was a considerable uptick
2:33 in sessions with and this is when the app freezes.
2:37 As it turns out, by looking just at search latency as the metric to improve,
2:42 we forgot something.
2:44 We had moved that web fragment initialization from out of the search
2:49 latency time right into a highly contested start up latency block of work.
2:54 Oops And so we learned.
2:58 One, we need to pay attention to both search and start up latency two.
3:05 We cut a lot of search latency.
3:08 If we could somehow move the web fragment initialization earlier.
3:13 Three the Android Google Apps initialization
3:17 is a very long and complicated process, which begs the question,
3:21 are there improvements we can make within that initialization stage.
3:25 And if we could do that, can we use any freed up processing capacity to do
3:30 at least some of that web fragment
3:33 initialization before we get to the query submission.
3:36 A good place to start here would be with ironing
3:38 out the startup flow in the Quick Search box.
3:41 Critical user journey.
3:43 This is the Quick Search box.
3:46 The QSB critical user journey makes up roughly a third of AJ's visits,
3:51 and here is a trace of a typical QSB startup and initial search from early 2025.
3:59 As you can see, there are a lot of densely packed
4:02 spans going on, and let's highlight when various steps are taking place.
4:07 Here the activity begins as in our app starts
4:10 in a window that pops up on the screen.
4:13 Next, the Chrome Custom Tabs are pre-warmed.
4:16 Wait, why the CCTV or Chrome Custom Tabs is what
4:20 you're looking at when it looks like you're in Chrome.
4:23 After you click on a blue SERP link.
4:25 So let's put the out of order boxes in red.
4:29 Next the suggestions are displayed.
4:32 The secondary UI is drawn like the header and bottom navigation bar.
4:36 Then the keyboard comes up.
4:38 At this point the search box is interactive.
4:42 Next, we seem to have several seconds
4:44 when nothing happens on the main UI thread.
4:47 And please note the giant red arrow.
4:50 Next, we seem to have a locked WebView initialization,
4:53 and here is where the user starts interacting with the app via key press.
4:58 And now here is where AGA initializes the WebView instance.
5:04 That seems awfully late,
5:07 especially since WebView is the component that renders the SERP.
5:10 The search results page and handles all its events like the clicks, scrolls,
5:15 navigation, et cetera which we need before we could initialize our web fragment.
5:21 Then it seems like the user picks one of the suggestions and clicks on it.
5:25 After that, within the red box, we begin tracking our SERP search latency,
5:30 where we still have our web fragment
5:33 initialization and most of our WebView initialization.
5:37 Taking a second look without the trace distracting us,
5:40 we can look at that several second gap as an area of opportunity.
5:45 And here's a good analogy for a situation.
5:47 The chef is preparing dessert.
5:49 The secondary UI while the customer is yet to receive their main course.
5:53 That's the interactive UI to start typing and clicking.
5:56 And while the chef guarantees rapid dessert service,
5:59 that does not translate into customer satisfaction,
6:03 a cold main course due to delays risks customer rejection.
6:07 And this is a parallel to AJ's unfortunately high cancellation rate.
6:12 And so we decided to tackle our non-optimal flow.
6:16 The first step was to prioritize the keyboard.
6:18 It didn't seem reasonable to make a user wait
6:21 for secondary UI to be drawn before giving them the keyboard.
6:25 So let's put it earlier and move it over for space.
6:28 Now there was a slight search latency regression.
6:31 We hypothesized that this was mainly on 0 prefix suggestions clicks.
6:36 These were probably users who tapped
6:37 on suggestions before WebView was done initializing,
6:40 and we also hypothesized that no one was actually getting to the SERP later.
6:45 However, our other performance metrics were much improved.
6:49 In particular, Startup interactive latency was greatly reduced.
6:53 Also, this keyboard launch greatly
6:55 reduced quick cancellations for text searches.
6:58 The 0 prefix slice especially.
7:00 Even more excitedly, this drove growth.
7:03 This launch was actually the largest growth drive
7:06 for at least the agardh latency team for the year,
7:09 and was the most significant growth for all of agardh in Q2.
7:13 We also discovered that we were pre-warming Chrome Custom Tabs,
7:16 the same Chrome Custom Tabs that aren't used until user clicks
7:20 on a link in the SERP before suggestions were even displayed.
7:24 Moving that to just before the secondary
7:27 UI drawers gave a small search latency improvement,
7:30 but more importantly, a considerable improvement in the time to interactive.
7:35 Next, we figured out a way
7:36 to start tackling the giant web fragment initialization.
7:39 Thanks to the WebView team,
7:41 we were able to call both a WebView startup and profile pre-warming.
7:45 We realized that we could do this pre-warming once
7:48 the suggestions and keyboard were available to the user.
7:51 We had already been doing some pre-warming,
7:54 but adding in the WebView profile alleviated some
7:56 of the work from within the later web fragment initialization.
8:00 We saw a modest search latency reduction at this change,
8:04 as we had freed up some space after the user
8:07 input by moving the pre-warm WebView into the area of opportunity.
8:11 We found that we could attach an independent web fragment,
8:15 not a particular instance,
8:16 but it did a lot of the same initialization, we needed.
8:20 Once the user starts typing,
8:22 this actually gave us a considerable win in search latency.
8:26 Once we finished placing the startup and profile prewarming,
8:29 we found a place for the majority
8:30 of the rest of that web fragment initialization.
8:34 By pre-warming the WebView instance, right after the WebView profile,
8:37 we were able to cut off a lot of time from search latency,
8:42 and outside of Google you'd use the WebView compat startup WebView here.
8:46 And so we came to our updated quick
8:49 search box critical user journey by mid 2025.
8:53 Activity start suggestions displayed keyboard up.
8:56 At which point the search box is interactive and as you see, no more gap.
9:00 Instead we pre-warm WebView profile WebView instance CT secondary UI drawers.
9:07 Then the user starts typing and we attach the independent web fragment.
9:12 The user clicks the suggestion and off we go into SERP
9:14 latency with a much smaller job of web fragment initialization.
9:20 As for next steps, we have plenty more ideas,
9:23 as this approach of re-arranging pieces of our initialization into the correct
9:28 order has shown to have quite a bit of headroom.
9:31 In short, our strategy of intentional initialization
9:34 is delete things we don't actually need.
9:38 You might be shocked at how much
9:41 unused code dependency injection we've been initializing.
9:44 We move blocks of code earlier or later,
9:47 depending on by when they're actually needed.
9:50 Optimize sometimes we're using slow methodology,
9:54 and sometimes we need to break up big initialization into smaller,
9:58 more easily placeable chunks.
10:00 And as blocks are made shorter or removed, we can leverage the newly found gaps
10:06 as new homes for initialization chunk placement.
10:09 And we all love recursion.
10:11 And we can apply this concept to other
10:13 flows such as home screen to suggest and notifications,
10:17 and even more keyboard initialization.
10:20 As an example, our current iteration is working on the keyboard again,
10:23 though considerable improvements have already been
10:26 made to the keyboard start up latency, it's still been frustratingly slow,
10:30 especially in comparison to Google Go's performance,
10:33 and we have been looking into whether it's possible to make it faster.
10:37 Looking at this trace, we can see where the activity starts,
10:41 where the suggestions fragment is initialized,
10:43 followed by the search box fragment.
10:46 Then we get the window, focus on the search box,
10:50 then the suggestions are displayed and then the keyboard finally comes up.
10:54 There's a lot of work that goes on in other threads,
10:57 but the call for the keyboard cannot go
10:59 out until we have focused on the search box.
11:03 So something we've been exploring is,
11:05 can we change up this order and delay the suggestions
11:09 fragment initialization so that we could initialize the search box first.
11:14 What you can see here is a trace from a prototype we've been working on.
11:18 Here we explore initialization of the suggestions only once we
11:23 get to focus on the search box and call the keyboard.
11:26 In playing around with a polished version of this change,
11:30 the keyboard feels like it comes up considerably faster.
11:33 And so we've noticed quite a bit of improvement to the user experience.
11:36 Hopefully, our theory of applying intentional initialization here
11:40 will bring a positive change to everyone soon.
11:43 And so our main takeaways.
11:46 Intentional initialization leverage.
11:49 Great WebView resources.
11:51 Handy link here and apply it everywhere.
11:55 For more Android conference talks check out the documentation and thank you.