Android App Performance Optimization

Garima Singh
MindOrks
Published in
6 min readJul 4, 2017

Improving Android Application Performance

Developing Apps for the Android OS gives a lot of freedom to developers and access to an ever-growing user base to the app owner. However, the developers face many Android app development challenges in the process.

  • There are many android os version which developers find hard to keep up when it comes to development.
  • This becomes a big challenge in Android app development since there are nearly 170+ devices running the OS. Each device has different features with respect to screen size, camera buttons, keyboard forms, etc. , making it a development nightmare.

Keeping few things in mind we can improve the performance of our application. Following are the factors which degrade our app performance and the improvements which can be done.

Slow Rendering

Slow Rendering is the most common performance problem. Because what the the designers want from us and what we do, may not be the same and trying to do the best visuality, we can sometime fail in development.

Rendering is defined in terms of times which ensures that app is running Butterly smooth at a constant 60 FPS without any dropped or delayed frames.

What Causes Slow Rendering?

System tries to attempt redrawn your activities after every 16ms. This means that our app has to do all the logic to update the screen in that 16 ms.

what if our app can’t complete the logic in 16 ms?

It’s called dropped frame. For example, if your calculation takes 24 ms, this case happens. System tried to draw a new picture to the screen, but it wasn’t ready. So it did not refresh anything. And this caused, user’s seeing the refreshed picture after 32 ms instead of 16ms. If even there is one dropped frame, the animation will start not to be seen smooth.

Following tools can be used to improve Rendering :

  1. Hierarchy Viewer

Hierarchy Viewer is a tool built into Android Device Monitor that allows you to inspect the properties and layout speed for each view in your layout hierarchy. It can help you find performance caused by the structure of your view hierarchy, helping you then simplify the hierarchy and reduce overdraw.

2. Profile GPU Rendering

Profile GPU Rendering gives a quick visual representation of how much time it takes to render the frames of a UI window relative to the 16-ms-per-frame benchmark.

Enable Profile GPU Rendering

On your mobile device, go to Settings > Developer Options.

  • In the Monitoring section, select Profile GPU Rendering.
  • In the Profile GPU Rendering popup, choose On screen as bars
  • Go to the app that you want to profile.

Visual Output of GPU Profiler

  • The horizontal axis shows time elapsing, and the vertical axis time per frame in milliseconds.
  • As you interact with your application, vertical bars show up on your screen.
  • Each vertical bar represents one frame of rendering.
  • The green line marks the 16 millisecond target. Every time a frame crosses the green line, app is missing a frame, and users may see this as stuttering images.

Application Launching Time

App launch can take place in one of two states, each affecting how long it takes for an application to become visible to user.

  1. Cold Start
  2. Warm Start

Cold Start

A cold start refers to an app’s starting from scratch, Cold starts happen in cases such as your app’s being launched for the first time since the device booted, or since the system killed the app.

At the beginning of a cold start, the system has three tasks. These tasks are:

  • Loading and launching the app.
  • Displaying a blank starting window for the app immediately after launch.
  • Creating the app process.

Warm Start

A warm start of your application is much simpler and lower-overhead than a cold start. In a warm start, all the system does is bring your activity to the foreground. If all of your application’s activities are still resident in memory, then the app can avoid having to repeat object initialisation, layout inflation, and rendering.

How to Resolve app launching Time delay?

  • Initialise only those objects that are immediately needed. For example, rather than creating global static objects, instead, move to a singleton pattern, where the app initialises the object for the first time it accesses them.
  • Flattening your view hierarchy by reducing redundant or nested layouts.
  • Move all resource initialisation so that the app can perform it lazily on a different thread.
  • Allow the app to load and display your views, and then later update visual properties that are dependent on bitmaps and other resources.

Layouts

Layouts are a key part of Android applications that directly affect the user experience. If poorly implemented, your layout can lead to a memory hungry application with slow UIs. Each widget and layout you add to your application requires initialisation, layout, and drawing. For example, using nested instances of LinearLayout can lead to an excessively deep view hierarchy.

How to Improve Layout Performance?

  1. Optimising Layout Hierarchies

Using the basic layout structures leads to the most efficient layouts. However, each widget and layout you add to your application requires initialisation, layout, and drawing. For example, using nested instances of LinearLayout can lead to an excessively deep view hierarchy. Furthermore, nesting several instances of LinearLayout that use the layout_weight parameter can be especially expensive as each child needs to be measured twice. This is particularly important when the layout is inflated repeatedly, such as when used in a ListView or GridView.

2. Re-using Layout with <Layouts>

Reusing layouts is particularly powerful as it allows you create reusable complex layouts. For example, a yes/no button panel, or custom progress bar with description text. It also means that any elements of your application that are common across multiple layouts can be extracted, managed separately, then included in each layout. So while you can create individual UI components by writing a custom View, you can do it even more easily by re-using a layout file.

3. Loading Views on Demand

Sometimes your layout might require complex views that are rarely used. Whether they are item details, progress indicators, or undo messages, you can reduce memory usage and speed up rendering by loading the views only when they are needed.

Power Usage

Battery Usage Reduction is also an important part of an android development as this optimisation will ultimately lead to retain the user, as many times the user uninstall the application because of the battery draining issue.

Tips for improving battery usage in an android application:

  • Reduce network calls as much as you can.
  • Avoid wake lock as much as Possible.
  • Use GPS carefully.
  • Use Alarm manager carefully.
  • Perform Batch Scheduling.

Thanks for reading this article. Be sure to click ❤ below to recommend this article if you found it helpful. It would let others get this article in feed and spread the knowledge.

--

--