Overdraw, Memory Leaks, ANR and Slow Rendering in Android Apps

Overdraw

Any jerks or lag or performance or slowness may antagonize a user from using the App. Overdraw might be one of the causes.

Overdraw is when a pixel on the screen drawn multiple times.
Represented in four stages, which are 1x, 2x, 3x, and 4x.

To Diagnose Overdraw, we can use developer options android and turn on the debug GPU overdraw.

Tutorial on turning on developer options and Debug GPU overdraw:

  1. Enable Developer options. Click on the Build Number multiple times.

Enable Developer Options
Fig 1. Enable Developer Options**

  1. Enable Debug GPU Overdraw.

Enable Debug GPU Overdraw
Fig 2. Enable GPU Overdraw**

Memory Leaks

ANR – Application Not Responding

App in the foreground and is unresponsive, user will get Application Not Responding – ANR.
If not in foreground, then it’s silently stopped.

Image description
Fig 3. ANR Dialog**

ANR Triggers

Usually when app can’t respond to user input on main thread or UI thread.
Preventing system from processing input events from users.

Examples:

  • Blocking I/O operation. Such as network access
  • Taking time building in-memory structure
  • Computing something expensive in Main or UI Thread

Android will trigger ANR when:

  • No responses to an input event – within 5 seconds
  • BroadcastReceiver doesn’t finish executing within 10-20 seconds

BroadcastReceiver is the one that listens for events either on app or system

Prevention of ANR

Keep the main or UI thread unblocked:

  • Don’t perform blocking or long-running applications
  • Minimize any lock contention – accessing same resources at the same time
  • Use threads strategically – worker threads

Usually 100-200ms is the threshold for slowness in an app

References

Slow Rendering

UI rendering is an act of generating a frame from your app and displaying it on the screen.

To Achieve 60fps - frames per second, each frames must be able to be renderd under 16ms

Identify Jank – Stuttering or unsmooth motion in app’s UI

Identifying jank can be difficult. Stated from Developer.Android there are 3 method for identifying jank:

  1. Visual inspection – fast
  2. Systrace – more detail, more data which also means more difficult to analyze
  3. Custom performance monitoring

Profile GPU Rendering also can be used to analyze GPU rendering and we can anlyze where is the bottleneck of the application

References

Leave a Reply