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 8: Finally... coding

Micro-optimizations

PreviousFlutter: State matters... Complex stuff aheadNextChapter 9: Data pipeline

Last updated 1 year ago

(By Mario Linares-Vásquez)


After having a taste of the mobile programming models, it is a good moment to learn about simple mobile programming practices that will save your... life when dealing with performance issues. These mobile practices are called micro-optimization.

A micro-optimization is a set of changes to the source code that (mostly at statement level) are intended to improve the performance on an app but are not intended to change the system design or architecture [^1]. It is possible you are already knoledgeable of micro-optimizations because they are widely promoted by linters and static analysis tools such as and ; though, in those tools, micro-optimizations are called as code-smells or bugs in the performance-related categories.

A clear example of micro-optimization is replacing String objects (in Java) with StringBuffers. Another example is to replace Collections with arrays of primitive types. A micro-optimization aims at improving the resources consumption by reducing the overhead introduced by sub-optimal API usages, code idioms, or personal programming practices.

A key aspect of micro-optimizations is that their impact, in some cases, depends on the data load and context. It means, applying micro-optimizations could have a minimal impact on resources consumption, because the improvement is only noticeable with certain amount of operations (or data) related to the statements that have the micro-optimization. This is the case of the String-related micro-optimizations, because the impact of the micro-optimizations depends on the size of the Strings and the amount of String operations.

There are also micro-optimizations that are proved to have a decent/noticeable impact independently of the work load. For example, remove unused resources is one of the MUST-DO micro-optimizations for mobile apps. The idea is to get rid not only of images, icons, files, you do not use in your app, but also strings that are defined in resources files (especially in the strings file of Android apps. Declare objects outside of loops is also a MUST-DO; this micro-optimization consist on avoiding declaring objects inside loops; objects should be declared outside loops and null-instantiated, so, the object instantiation is done in the loop (as in the image below).

Anyway, independently of the micro-optimization and its impact, it is always a very good idea to implement as many as you can, in particular, when coding mobile apps, because of the hardware constraints and the mobile OS policies. You can take advantage of existing linters and IDE features that automatically report to you micro-optimization opportunities. Micro-optimizations are a preventive way for dealing with potential performance issues.

[^1:] Mario Linares-Vásquez, Christopher Vendome, Michele Tufano, Denys Poshyvanyk, How developers micro-optimize Android apps, Journal of Systems and Software, Volume 130, 2017, Pages 1-23, ISSN 0164-1212, https://doi.org/10.1016/j.jss.2017.04.018.

Check the proposed by Google, and the article by Colt McAnlis.

performance tips
The truth about Preventative Optimizations
SonarQube
FindBugs