SlideShare a Scribd company logo
1 of 30
Android APP Performance
Tips and Tools
Saksham Keshri
Eng. Manager, Saavn
Twitter - sakshamkeshri
Agenda
Tips and Tools
Battery Consumption
App Launch Time
App Size
UI Rendering
Memory Usage
It’s an ongoing process, you need to keep track of things in each release.
Performance is a feature.
Battery Consumption
Tips
Optimizing User-Initiated Network Use
1. Pre-fetch Network Data
2. Do not attempt to make unnecessary n/w connections if the n/w connection state is already known.
3. Reduce the Number of Connections by reuse existing connections.
Optimizing App-Initiated Network Use
1. Batch and Schedule Network Requests by using Job schedulers - Firebase job dispatcher. Doze mode.
2. Optimizing Server-Initiated Network Use by using push technology to send server updates.
3. Optimizing General Network Use
a. If n/w is bad, do not refresh ad too often.
b. Compress Data
c. Cache Files Locally
d. Optimize Pre-Fetch Cache Size
Wake lock
Battery Consumption
Tools
1. Battery Historian
Host
docker run -p <port> gcr.io/android-battery-historian/stable:3.0 --port <port>
Reset
adb kill-server
adb shell dumpsys batterystats --enable full-wake-history
adb shell dumpsys batterystats --reset
Run Test Case, Analyze via Battery Historian
2. Android Monitor
3. Different HTTP Call tagging
Battery Historian
Bug report 1 - Caching Enabled.
Bug report 2 - Caching Disabled.
Battery Consumption
Battery Historian
Battery Consumption
Battery Historian
Battery Historian
Battery Consumption
Battery Historian
Battery Historian - APP Specific
Battery Consumption
Battery Historian
Battery Historian - Comparison
App Launch Time
Tips
Load with cached data and then refresh.
Light XML.
Delay time taking tasks.
Tools
i/activitymanager displayed
Activity.reportFullyDrawn()
App Size
Tips
Shrink Your Code and Resources
Use drawable objects, reuse resources, compress png/jpeg
Last choice : Build multiple APKs to support multiple screen densities or Application Binary Interfaces (ABIs)
Tools
APK Analyzer - Tool
App Size
App Size
APK Analyzer - Compare
Tips
Avoid nested hiererarcy
Avoid layout_weight parameter as each child needs to be measured twice.
Merge tag with Include to avoid one more level of hierarchy.
Viewstub to lazy load views.
Simple layout when when the layout is inflated repeatedly, such as when used in a ListView or GridView.
Use constraint layout over relativelayout.
Tools
Hierarchy Viewer
Lint tool
Profile GPU Rendering
Layout Inspector
UI Rendering
UI Rendering - Overdraw
Waste GPU Time to paint pixels which user don’t
see.
Removing unneeded backgrounds in layouts
Layout Inspector
Flattening view hierarchy
Reducing transparency
UI Rendering - Double Taxation
Layout Matters
Layout-and-measure iterations to measure the view’s finalize position.
First layout-and-measure pass to calculates each child object’s position and size
Uses this data, also taking object weights into account, to figure out the proper position of correlated views.
Finalize objects’ positions by performing a second layout pass
Layout-and-measure multiple passes can’t be completely avoided. But avoid in case of
1. Root element
2. Deep view hierarchy beneath it.
3. Inflating it several times as in case of list view.
UI Rendering - Use Merge Tag
<RelativeLayout><include
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"la
yout="@layout/header_layout"/></Relati
veLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Child1"
android:id="@+id/child1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/child1"
android:text="Child2"/>
</RelativeLayout>
<merge
xmlns:android="http://schemas.android.
com/apk/res/android">
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Child1"
android:id="@+id/child1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/child1"
android:text="Child2"/>
</merge>
UI Rendering - Use ViewStub
ViewStub - lightweight view.
Each ViewStub simply needs to include the
android:layout attribute to specify the layout to
inflate.
Also, useful to have same generic xml and
inflate the part as per case.
findViewById(R.id.stub)).setVisibility(View.VISI
BLE);
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="visible"
/>
<ViewStub
android:id="@+id/stub"
android:inflatedId="@+id/inflatedLayoutId"
android:layout="@layout/loaded_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<include layout="@layout/empty_view"
android:id="@+id/empty_view" android:visibility="gone" />
</FrameLayout>
UI Rendering
Hierarchy Viewer
Memory Usage
Tips
Use services sparingly
Big no to static activities/views
Non-static nested classes - Avoid unintentional reference to any object
Unregister listeners when not in use. - Instance will keep a reference around long after the referenced object has
been terminated. Worst case - Object is activity.
Tools
Leak canary from square.
The Memory Monitor - Heap updates.
HPROF Viewer and Analyzer
Eclipse MAT
The Allocation Tracker
Leads to memory out of exception or nasty Illegal state exception.
Memory Usage - Registering listeners
public class LeaksActivity extends Activity implements LocationListener {
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leaks);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
TimeUnit.MINUTES.toMillis(5), 100, this);
}
}
Memory Usage - Registering listeners
public class LeaksActivity extends Activity implements LocationListener {
private LocationManager locationManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_leaks);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
TimeUnit.MINUTES.toMillis(5), 100, this);
}
@Override
protected void onDestroy() {
locationManager.removeUpdates(this);
super.onDestroy();
}
}
Memory Usage - Inner Class and anonymous class
public class AsyncActivity extends Activity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_async);
textView = (TextView) findViewById(R.id.textView);
new BackgroundTask().execute();
}
private class BackgroundTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... params) {
// http call to get some string
return "some string";
}
@Override
protected void onPostExecute(String result) {
textView.setText(result);
}
}
}
Memory Usage - Inner Class and anonymous class
public class AsyncActivity extends Activity {
TextView textView;
AsyncTask task;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_async);
textView = (TextView) findViewById(R.id.textView);
task = new BackgroundTask(textView).execute();
}
@Override
protected void onDestroy() {
task.cancel(true);
super.onDestroy();
}
private static class BackgroundTask extends AsyncTask<Void, Void, String> {
private final TextView resultTextView;
public BackgroundTask(TextView resultTextView) {
this.resultTextView = resultTextView;
}
@Override
protected String doInBackground(Void... params) {
// Do background work. Code omitted.
return "some string";
}
}
}
Memory Usage - Android Monitor
Image Credit : Credit I
Memory Usage
HPROF Analyzer
Image Credit : Credit II
Memory Usage
Eclipse MAT
Eclipse MAT
Sources
Official android performance
Battery Historian
https://medium.com/@elifbon/android-application-performance-step-4-battery-
b1f88d096b1e
Memory Leak, Credit I & II
https://medium.com/freenet-engineering/memory-leaks-in-android-identify-treat-
and-avoid-d0b1233acc8
Rendering-
https://medium.com/@elifbon/android-application-performance-step-1-rendering-
ba820653ad3
Thank You!
Questions?
Saksham Keshri
Eng. Manager, Saavn
Twitter - sakshamkeshri

More Related Content

Similar to Android app performance

W 0300 codingfor_life-batterylifethatis
W 0300 codingfor_life-batterylifethatisW 0300 codingfor_life-batterylifethatis
W 0300 codingfor_life-batterylifethatisjicheng687
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...Akira Hatsune
 
Quick guide to plan and execute a load test
Quick guide to plan and execute a load testQuick guide to plan and execute a load test
Quick guide to plan and execute a load testduke.kalra
 
IRJET- Application Backup and Restore across Multiple Devices
IRJET-	 Application Backup and Restore across Multiple DevicesIRJET-	 Application Backup and Restore across Multiple Devices
IRJET- Application Backup and Restore across Multiple DevicesIRJET Journal
 
Android Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the TrenchesAndroid Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the TrenchesAnuradha Weeraman
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceOleksii Prohonnyi
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptxMugiiiReee
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsLuis Cruz
 
Attribute Reduction:An Implementation of Heuristic Algorithm using Apache Spark
Attribute Reduction:An Implementation of Heuristic Algorithm using Apache SparkAttribute Reduction:An Implementation of Heuristic Algorithm using Apache Spark
Attribute Reduction:An Implementation of Heuristic Algorithm using Apache SparkIRJET Journal
 
SVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java RuntimeSVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java RuntimeVan Riper
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Lou Sacco
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 seriesopenbala
 
Asp dot net lifecycle in details
Asp dot net lifecycle in detailsAsp dot net lifecycle in details
Asp dot net lifecycle in detailsAyesha Khan
 
Why ASP.NET Development is Important?
Why ASP.NET Development is Important?Why ASP.NET Development is Important?
Why ASP.NET Development is Important?Ayesha Khan
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperVinay Kumar
 

Similar to Android app performance (20)

W 0300 codingfor_life-batterylifethatis
W 0300 codingfor_life-batterylifethatisW 0300 codingfor_life-batterylifethatis
W 0300 codingfor_life-batterylifethatis
 
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...MVP Community Camp 2014 - How to useenhanced features of Windows 8.1 Store ...
MVP Community Camp 2014 - How to use enhanced features of Windows 8.1 Store ...
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Quick guide to plan and execute a load test
Quick guide to plan and execute a load testQuick guide to plan and execute a load test
Quick guide to plan and execute a load test
 
Vue.js basics
Vue.js basicsVue.js basics
Vue.js basics
 
IRJET- Application Backup and Restore across Multiple Devices
IRJET-	 Application Backup and Restore across Multiple DevicesIRJET-	 Application Backup and Restore across Multiple Devices
IRJET- Application Backup and Restore across Multiple Devices
 
Intro react js
Intro react jsIntro react js
Intro react js
 
Android Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the TrenchesAndroid Best Practices - Thoughts from the Trenches
Android Best Practices - Thoughts from the Trenches
 
Dive into Angular, part 5: Experience
Dive into Angular, part 5: ExperienceDive into Angular, part 5: Experience
Dive into Angular, part 5: Experience
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android AppsUsing Automatic Refactoring to Improve Energy Efficiency of Android Apps
Using Automatic Refactoring to Improve Energy Efficiency of Android Apps
 
Attribute Reduction:An Implementation of Heuristic Algorithm using Apache Spark
Attribute Reduction:An Implementation of Heuristic Algorithm using Apache SparkAttribute Reduction:An Implementation of Heuristic Algorithm using Apache Spark
Attribute Reduction:An Implementation of Heuristic Algorithm using Apache Spark
 
IRJET-Cleaner Drone
IRJET-Cleaner DroneIRJET-Cleaner Drone
IRJET-Cleaner Drone
 
SVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java RuntimeSVCC Google App Engine: Java Runtime
SVCC Google App Engine: Java Runtime
 
Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014Meteor Meet-up San Diego December 2014
Meteor Meet-up San Diego December 2014
 
Windows phone 7 series
Windows phone 7 seriesWindows phone 7 series
Windows phone 7 series
 
Asp dot net lifecycle in details
Asp dot net lifecycle in detailsAsp dot net lifecycle in details
Asp dot net lifecycle in details
 
Why ASP.NET Development is Important?
Why ASP.NET Development is Important?Why ASP.NET Development is Important?
Why ASP.NET Development is Important?
 
Tuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paperTuning and optimizing webcenter spaces application white paper
Tuning and optimizing webcenter spaces application white paper
 

Recently uploaded

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 

Recently uploaded (20)

Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Android app performance

  • 1. Android APP Performance Tips and Tools Saksham Keshri Eng. Manager, Saavn Twitter - sakshamkeshri
  • 2. Agenda Tips and Tools Battery Consumption App Launch Time App Size UI Rendering Memory Usage It’s an ongoing process, you need to keep track of things in each release. Performance is a feature.
  • 3. Battery Consumption Tips Optimizing User-Initiated Network Use 1. Pre-fetch Network Data 2. Do not attempt to make unnecessary n/w connections if the n/w connection state is already known. 3. Reduce the Number of Connections by reuse existing connections. Optimizing App-Initiated Network Use 1. Batch and Schedule Network Requests by using Job schedulers - Firebase job dispatcher. Doze mode. 2. Optimizing Server-Initiated Network Use by using push technology to send server updates. 3. Optimizing General Network Use a. If n/w is bad, do not refresh ad too often. b. Compress Data c. Cache Files Locally d. Optimize Pre-Fetch Cache Size Wake lock
  • 4. Battery Consumption Tools 1. Battery Historian Host docker run -p <port> gcr.io/android-battery-historian/stable:3.0 --port <port> Reset adb kill-server adb shell dumpsys batterystats --enable full-wake-history adb shell dumpsys batterystats --reset Run Test Case, Analyze via Battery Historian 2. Android Monitor 3. Different HTTP Call tagging
  • 5. Battery Historian Bug report 1 - Caching Enabled. Bug report 2 - Caching Disabled.
  • 10. App Launch Time Tips Load with cached data and then refresh. Light XML. Delay time taking tasks. Tools i/activitymanager displayed Activity.reportFullyDrawn()
  • 11. App Size Tips Shrink Your Code and Resources Use drawable objects, reuse resources, compress png/jpeg Last choice : Build multiple APKs to support multiple screen densities or Application Binary Interfaces (ABIs) Tools APK Analyzer - Tool
  • 14. Tips Avoid nested hiererarcy Avoid layout_weight parameter as each child needs to be measured twice. Merge tag with Include to avoid one more level of hierarchy. Viewstub to lazy load views. Simple layout when when the layout is inflated repeatedly, such as when used in a ListView or GridView. Use constraint layout over relativelayout. Tools Hierarchy Viewer Lint tool Profile GPU Rendering Layout Inspector UI Rendering
  • 15. UI Rendering - Overdraw Waste GPU Time to paint pixels which user don’t see. Removing unneeded backgrounds in layouts Layout Inspector Flattening view hierarchy Reducing transparency
  • 16. UI Rendering - Double Taxation Layout Matters Layout-and-measure iterations to measure the view’s finalize position. First layout-and-measure pass to calculates each child object’s position and size Uses this data, also taking object weights into account, to figure out the proper position of correlated views. Finalize objects’ positions by performing a second layout pass Layout-and-measure multiple passes can’t be completely avoided. But avoid in case of 1. Root element 2. Deep view hierarchy beneath it. 3. Inflating it several times as in case of list view.
  • 17. UI Rendering - Use Merge Tag <RelativeLayout><include android:id="@+id/header_layout" android:layout_width="match_parent" android:layout_height="match_parent"la yout="@layout/header_layout"/></Relati veLayout> <RelativeLayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Child1" android:id="@+id/child1"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/child1" android:text="Child2"/> </RelativeLayout> <merge xmlns:android="http://schemas.android. com/apk/res/android"> android:layout_width="wrap_content" android:layout_height="wrap_content"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Child1" android:id="@+id/child1"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/child1" android:text="Child2"/> </merge>
  • 18. UI Rendering - Use ViewStub ViewStub - lightweight view. Each ViewStub simply needs to include the android:layout attribute to specify the layout to inflate. Also, useful to have same generic xml and inflate the part as per case. findViewById(R.id.stub)).setVisibility(View.VISI BLE); <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/frame" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:visibility="visible" /> <ViewStub android:id="@+id/stub" android:inflatedId="@+id/inflatedLayoutId" android:layout="@layout/loaded_view" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <include layout="@layout/empty_view" android:id="@+id/empty_view" android:visibility="gone" /> </FrameLayout>
  • 20. Memory Usage Tips Use services sparingly Big no to static activities/views Non-static nested classes - Avoid unintentional reference to any object Unregister listeners when not in use. - Instance will keep a reference around long after the referenced object has been terminated. Worst case - Object is activity. Tools Leak canary from square. The Memory Monitor - Heap updates. HPROF Viewer and Analyzer Eclipse MAT The Allocation Tracker Leads to memory out of exception or nasty Illegal state exception.
  • 21. Memory Usage - Registering listeners public class LeaksActivity extends Activity implements LocationListener { private LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_leaks); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TimeUnit.MINUTES.toMillis(5), 100, this); } }
  • 22. Memory Usage - Registering listeners public class LeaksActivity extends Activity implements LocationListener { private LocationManager locationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_leaks); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, TimeUnit.MINUTES.toMillis(5), 100, this); } @Override protected void onDestroy() { locationManager.removeUpdates(this); super.onDestroy(); } }
  • 23. Memory Usage - Inner Class and anonymous class public class AsyncActivity extends Activity { TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_async); textView = (TextView) findViewById(R.id.textView); new BackgroundTask().execute(); } private class BackgroundTask extends AsyncTask<Void, Void, String> { @Override protected String doInBackground(Void... params) { // http call to get some string return "some string"; } @Override protected void onPostExecute(String result) { textView.setText(result); } } }
  • 24. Memory Usage - Inner Class and anonymous class public class AsyncActivity extends Activity { TextView textView; AsyncTask task; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_async); textView = (TextView) findViewById(R.id.textView); task = new BackgroundTask(textView).execute(); } @Override protected void onDestroy() { task.cancel(true); super.onDestroy(); } private static class BackgroundTask extends AsyncTask<Void, Void, String> { private final TextView resultTextView; public BackgroundTask(TextView resultTextView) { this.resultTextView = resultTextView; } @Override protected String doInBackground(Void... params) { // Do background work. Code omitted. return "some string"; } } }
  • 25. Memory Usage - Android Monitor Image Credit : Credit I
  • 26. Memory Usage HPROF Analyzer Image Credit : Credit II
  • 29. Sources Official android performance Battery Historian https://medium.com/@elifbon/android-application-performance-step-4-battery- b1f88d096b1e Memory Leak, Credit I & II https://medium.com/freenet-engineering/memory-leaks-in-android-identify-treat- and-avoid-d0b1233acc8 Rendering- https://medium.com/@elifbon/android-application-performance-step-1-rendering- ba820653ad3
  • 30. Thank You! Questions? Saksham Keshri Eng. Manager, Saavn Twitter - sakshamkeshri

Editor's Notes

  1. One of the major reason for uninstall. Major reason of the battery drain - HTTP call - makes the n/w radio on and off.
  2. Comparison /Users/saksham/Documents/android/battery/lab/latest/normal/player1.zip Dump app wise and couple of more sliides
  3. First impression is the last impression. User might switch to the other app, if it does not load instantaneously.
  4. Directly proportional to app installs.
  5. Double Taxation https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies.html Profile GPU rendering GPU tracker
  6. Double Taxation https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies.html Profile GPU rendering GPU tracker
  7. Double Taxation https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies.html Profile GPU rendering GPU tracker
  8. Double Taxation https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies.html Profile GPU rendering GPU tracker
  9. Double Taxation https://developer.android.com/topic/performance/rendering/optimizing-view-hierarchies.html Profile GPU rendering GPU tracker
  10. Measure, Layout, Draw