Book
  • Introduction
  • Welcome !!
  • Chapter 1: The mobile ecosystem
    • Fragmentation is the devil
    • There is more than one type of mobile app
    • ... more than one type of app
    • ... one type of app
    • Under pressure (ee da de da de) !!
    • Further reading!!
  • Chapter 2: Let's start with design thinking
    • A taste of design thinking
    • The five steps
    • Design for everybody
    • Accessibility in mobile apps
  • Chapter 3: Give me a context and I will give you an app
    • Users
    • Personas? Users ? What is the difference?
    • Please, help me to model the context
    • The context canvas
  • Chapter 4: Powerful models
    • Data architecture is the foundation of analytics
    • From data to information and knowledge
    • Information/Knowledge in our mobile ecosystem
    • Questions to ask yourselves when building and classifying questions
    • The visualization-data map
    • On the scene: describing how personas interact with your app
  • Chapter 5: A GUI is better than two thousand words
    • 'Good to Go:' Let's explore the Design Systems
    • Designing GUI Mocks
    • No prototype... no deal
  • Chapter 6: About mobile operating systems ... and other deamons
    • The Android OS ... son of LINUX
    • iOS son of Darwin? or is it iOS son of UNIX?
    • Kernels
  • Chapter 7: Yes, software architecture matters !!
    • Self-test time
    • About design and design constraints
    • Architects' mojo: styles and patterns
    • What you need is a tactic !!
    • Self-test time 2 (for real)
    • Further reading
  • Chapter 8: Finally... coding
    • MVC, MVVM, MV*, MV...What?
    • Programming models: the Android side
    • Hello Jetpack, my new friend... An Android Jetpack Introduction
    • Programming models: the iOS side
    • Controllers and more controllers
    • Flutter son of... simplicity
    • Programming models: Flutter?
    • Flutter: State matters... Let´s start simple
    • Flutter: State matters... Complex stuff ahead
    • Micro-optimizations
  • Chapter 9: Data pipeline
    • Generalities data pipelines
    • Data storage types
    • Types of data pipelines
  • Chapter 10: Error Retrieving Chapter 10
    • Eventual Connectivity on Mobile Apps
    • How to handle it on Android
  • Chapter 11: The jewel in the crown: Performance
    • As fast as a nail
    • Memory bloats
    • Energy leaks
    • Final thoughts
  • Chapter 12. Become a performance bugs exterminator
    • Weak or strong?
    • Micro-optimizations
    • The single thread game !!
    • Using multi-threading like a boss !!
    • Caching
    • Avoiding memory bloats
    • Further readings
Powered by GitBook
On this page
  1. Chapter 11: The jewel in the crown: Performance

As fast as a nail

PreviousChapter 11: The jewel in the crown: PerformanceNextMemory bloats

Last updated 1 year ago

(By Mario Linares-Vásquez)

(Free image by Jingxuan Chi on )


Mobile apps are gesture-driven, which means that the interaction between the user and the app is mostly done through gestures performed on the phone's display. In addition, mobile devices are an "essential" element for humans. Therefore, users always expect mobile apps to react quickly to their commands !!. So, it is a best practice to know and apply the "best practices" for creating mobile apps that react as fast as possible to users' commands. First, let's talk about one of the most common problems that impact apps' performance: GUI lagging and ANR errors.

Mobile apps, by default, follow a single thread policy. It means that the same thread is in charge of listening for external events, painting the GUI, and executing any operation the app code dictates. This thread is called main thread or GUI thread. So, it is like when you are listening and replying to your best friend (face to face) but at the same time you have to finish a differential equations midterm; at some point in the conversation you will not reply to your friend as fast as she/he expects. Long-term or computational expensive tasks, when executed on the main thread, impacts apps' responsiveness, because when the thread is busy with a long task there is no room for reacting to other events form the GUI or the system.

¿Have you experienced a lag when talking to somebody? Probably yes.

Running time consuming tasks on the main thread leads to two problems: GUI lags and ANR errors. The former can be identified in the GUI because the transitions and animations are not smooth as expected or because the GUI does not respond as fast as expected; the frame rate in Android is 16 ms to assure nice UI drawing, therefore, any long tasks on the main thread can itenfere on the 16ms frame rate. In summary, you can see lags or delays in the GUI and it does not look natural, the app is frozen by a very short period. The ANRs (Application Not Responding) errors are more intrusive because in this case the application hangs for a while, therefore, it does not respond to any event from the events; the consequence for an ANR is an annoying dialog that shows up in the display, like the one depicted below:

In the case of Android apps, the dialog is thrown by the operating system when it detects that the GUI does not respond in 5 seconds. ANRs are also generated in Android apps when a broadcast receiver has not finished its execution within 10 seconds.

You can read more about ANRs an GUI lags in Android apps in the following articles from the Android developer guide , , .

Keeping your app responsive
ANRs
Slow Rendering
Unsplash