SlideShare una empresa de Scribd logo
1 de 28
{ Andromance 
Android Performance Optimization 
O. Mert Şimşek 
/orhunmertsimsek 
mertsimsek.net 
4pps.co
Orhun Mert Şimşek 
• Co-Founder & CEO of 4pps 
• Android & iOS Developer 
• Educational Responsible at 
GDG Ankara 
• Android Evangelist
Let’s Boost the App
Use Splash If You Need 
It is better to show a splash, instead of grotty progress bars
internal Getters & Setters? 
Without a JIT, direct field access is about 3x faster than invoking a trivial getter. With the JIT (where 
direct field access is as cheap as accessing a local), direct field access is about 7x faster than invoking 
a trivial getter.* 
(*): http://developer.android.com/training/articles/perf-tips.html
StrictMode 
If you think that you might be doing some bad things accidentally, 
you should use StrictMode 
It is commonly used to detect accidental network or disc 
access on the UI thread.
StrictMode 
public void onCreate() { 
if (DEVELOPER_MODE) { 
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 
.detectDiskReads() 
.detectDiskWrites() 
.detectNetwork() // or .detectAll() for all detectable problems 
.penaltyLog() 
.build()); 
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() 
.detectLeakedSqlLiteObjects() 
.detectLeakedClosableObjects() 
.penaltyLog() 
.penaltyDeath() 
.build()); 
} 
super.onCreate(); 
} 
An example
DDMS
Use Hierarchy Viewer 
You can determine layers and some performance 
stats of UI with this tool 
Hard to use but very effective!
Use Hierarchy Viewer
Use Hierarchy Viewer
Use Less Objects, More Primitives 
Creating an object is extremely: EXPENSIVE! 
… but «primitive» is not! 
Using a 2 different integer array is more 
efficient than using object arrays like 
fooBar(int,int) 
badArray = new FooBar[] { new FooBar(5,8) , new FooBar(84,2) }; 
firstCoolArray = new int[] { 5, 84 }; 
secondCoolArray = new int[] { 8 , 2 };
How to Search a 2D Array? 
Search first for row, then column 
TO DO 
for (int i = 0; i < foo.length ; i++) { 
for (int j = 0; j < foo.length ; j++) { 
process(foo[i,j]); 
} 
} 
NOT TO DO 
for (int i = 0; i < foo.length ; i++) { 
for (int j = 0; j < foo.length ; j++) { 
process(foo[j,i]); 
} 
}
Use «Static» as Possible 
It is 15% - 20% faster! 
Static variables are initialized only once , at the start of 
the execution. 
And also use «static final» for your constants
«Lint» Usage 
The lint tool checks your Android project source files for potential 
bugs and optimization improvements for correctness, security, 
performance, usability, accessibility, and internationalization. * 
http://developer.android.com/tools/debugging/improving-w-lint.html
«Lint» Usage 
In Eclipse it is easy to use, just one click! 
In command line: 
«lint [flags] <project directory>» 
«lint myproject» 
«lint --check MissingPrefix myproject»
Reusable Layouts 
It is commonly used for title bars, yes-no button panels etc. 
Very easy to implement: 
Create a layout and use it in another layout with «<include ../>» tag 
<include layout="@layout/titlebar"/>
Do Your Hard-Work on Background Threads 
It is forbidden to make network processes in main thread, 
since Android 3.0 
How about Instagram? When you finished writing some 
hashtags and pressed to send button, 
It had been posted just a while ago!
View Holder for ListView Objects 
A ViewHolder object stores each of the 
component views inside the ListView object, 
so you can immediately access them without 
the need to look them up repeatedly. 
static class ViewHolder { 
TextView text; 
TextView timestamp; 
ImageView icon; 
} 
ViewHolder holder = new ViewHolder(); 
holder.icon = (ImageView) 
convertView.findViewById(R.id.listitem_image); 
holder.text = (TextView) convertView.findViewById(R.id.listitem_text); 
… 
Smooth!
XML Drawables 
PNG’s, JPG’s and others are big sized and 
a hard work for mobile device. 
But creating an image with XML is very cheap 
and it is more efficient than you expected. 
Using a 400 kb background image or using an Xml 
drawable which has size of just 300 bytes?
XML Drawables 
<?xml version="1.0" encoding="UTF-8"?> 
<shape 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="rectangle"> 
<stroke 
android:width="3dp" 
android:color="#000000" /> 
<gradient 
android:endColor="#F5CD7A" 
android:startColor="#657892" 
android:angle="90" /> 
</shape>
Handling Overdraws 
The most important part of performance. – If you ask me! 
Since Android 4.2, we can see overdraws in our devices. 
Overdraw is simply, drawing a pixel more than once. 
It’s notation is also simple: 
• No color: No overdraw 
• Blue: 1x overdraw (pixel is drawed 2 times) 
• Green: 2x overdraw 
• Light Red: 3x overdraw 
• Dark Red: 4x or more overdraw (ALERT!)
Handling Overdraws 
Youtube Spotify
• Acceptable red areas 
• Mostly blue and green 
• Optimized by Romain Guy - 
The God of Android 
Performance Optimization
• JUST red areas 
• Whole screen is drawed 
more than 5 times 
• Probably haven’t checked 
for overdraws
Handling Overdraws 
How to avoid? 
Actually its secret is written at the last one 
• thumbnail.setBackgroundColor(0x0); 
• android:windowBackground="@null" 
• If a view will not used anymore, don’t make its visibility «INVISIBLE», 
make it «GONE» 
• And use a simple design!
Summary and Little Other Tips 
 Do use two parallel «int» arrays instead of array of objects (int,int) 
 Do use «primitive» instead of objects 
 Do use as possible as «static» methods 
 Do use «static final» for constants 
 Do use foreach instead of for 
 Do use as possible as Xml Drawables instead of images (jpg,png) 
 Don’t create unnecessary objects 
 Don’t allocate memory if you can work without it 
 Don’t use getters and setters inside the class 
 Don’t do your hard works on main thread 
and the most important one: 
 Don’t publish your app unless it doesn’t have performance problems!
Torment Is Over, That’s All! 
Thanks for listening! 
O. Mert Şimşek 
/orhunmertsimsek 
mertsimsek.net

Más contenido relacionado

La actualidad más candente

La actualidad más candente (17)

Java applets
Java appletsJava applets
Java applets
 
L18 applets
L18 appletsL18 applets
L18 applets
 
Titanium appcelerator best practices
Titanium appcelerator best practicesTitanium appcelerator best practices
Titanium appcelerator best practices
 
TiConnect: Memory Management in Titanium apps
TiConnect: Memory Management in Titanium appsTiConnect: Memory Management in Titanium apps
TiConnect: Memory Management in Titanium apps
 
Java applet
Java appletJava applet
Java applet
 
Java applets
Java appletsJava applets
Java applets
 
applet using java
applet using javaapplet using java
applet using java
 
Applet
AppletApplet
Applet
 
java applets
java appletsjava applets
java applets
 
ITFT- Applet in java
ITFT- Applet in javaITFT- Applet in java
ITFT- Applet in java
 
Java Applets
Java AppletsJava Applets
Java Applets
 
Java Applet
Java AppletJava Applet
Java Applet
 
Applet programming in java
Applet programming in javaApplet programming in java
Applet programming in java
 
Applet life cycle
Applet life cycleApplet life cycle
Applet life cycle
 
Applets
AppletsApplets
Applets
 
10 Golden Rules For Outstanding Titanium Apps
 10 Golden Rules For Outstanding Titanium Apps 10 Golden Rules For Outstanding Titanium Apps
10 Golden Rules For Outstanding Titanium Apps
 
Applet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java AppletsApplet Architecture - Introducing Java Applets
Applet Architecture - Introducing Java Applets
 

Similar a Andromance - Android Performance

Mobile Developer Summit 2012, Pune
Mobile Developer Summit 2012, PuneMobile Developer Summit 2012, Pune
Mobile Developer Summit 2012, PuneBhuvan Khanna
 
Big Trouble in Little Networks
Big Trouble in Little Networks Big Trouble in Little Networks
Big Trouble in Little Networks Stacy Devino
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)YangJerng Hwa
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidStanojko Markovik
 
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)Igalia
 
Big Trouble in Little Networks, new and improved
Big Trouble in Little Networks, new and improvedBig Trouble in Little Networks, new and improved
Big Trouble in Little Networks, new and improvedStacy Devino
 
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...maikroeder
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)David Truxall
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Gil Irizarry
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011sullis
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and DevelopmentOpersys inc.
 
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...Hafez Kamal
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introductionBirol Efe
 
[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...BeMyApp
 

Similar a Andromance - Android Performance (20)

Best practices android_2010
Best practices android_2010Best practices android_2010
Best practices android_2010
 
Mobile Developer Summit 2012, Pune
Mobile Developer Summit 2012, PuneMobile Developer Summit 2012, Pune
Mobile Developer Summit 2012, Pune
 
Big Trouble in Little Networks
Big Trouble in Little Networks Big Trouble in Little Networks
Big Trouble in Little Networks
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
Play framework
Play frameworkPlay framework
Play framework
 
Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)Reactive datastore demo (2020 03-21)
Reactive datastore demo (2020 03-21)
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
What's new with JavaScript in GNOME: The 2020 edition (GUADEC 2020)
 
Big Trouble in Little Networks, new and improved
Big Trouble in Little Networks, new and improvedBig Trouble in Little Networks, new and improved
Big Trouble in Little Networks, new and improved
 
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
Repoze Bfg - presented by Rok Garbas at the Python Barcelona Meetup October 2...
 
iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)iOS for Android Developers (with Swift)
iOS for Android Developers (with Swift)
 
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
Make Cross-platform Mobile Apps Quickly - SIGGRAPH 2014
 
jQuery quick tips
jQuery quick tipsjQuery quick tips
jQuery quick tips
 
Introduce Django
Introduce DjangoIntroduce Django
Introduce Django
 
Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
NanoSec Conference 2019: Code Execution Analysis in Mobile Apps - Abdullah Jo...
 
Java - A broad introduction
Java - A broad introductionJava - A broad introduction
Java - A broad introduction
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...[Ultracode Munich #4] Short introduction to the new Android build system incl...
[Ultracode Munich #4] Short introduction to the new Android build system incl...
 

Último

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Zilliz
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 

Último (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

Andromance - Android Performance

  • 1. { Andromance Android Performance Optimization O. Mert Şimşek /orhunmertsimsek mertsimsek.net 4pps.co
  • 2. Orhun Mert Şimşek • Co-Founder & CEO of 4pps • Android & iOS Developer • Educational Responsible at GDG Ankara • Android Evangelist
  • 4. Use Splash If You Need It is better to show a splash, instead of grotty progress bars
  • 5. internal Getters & Setters? Without a JIT, direct field access is about 3x faster than invoking a trivial getter. With the JIT (where direct field access is as cheap as accessing a local), direct field access is about 7x faster than invoking a trivial getter.* (*): http://developer.android.com/training/articles/perf-tips.html
  • 6. StrictMode If you think that you might be doing some bad things accidentally, you should use StrictMode It is commonly used to detect accidental network or disc access on the UI thread.
  • 7. StrictMode public void onCreate() { if (DEVELOPER_MODE) { StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() .detectDiskReads() .detectDiskWrites() .detectNetwork() // or .detectAll() for all detectable problems .penaltyLog() .build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() .detectLeakedSqlLiteObjects() .detectLeakedClosableObjects() .penaltyLog() .penaltyDeath() .build()); } super.onCreate(); } An example
  • 9. Use Hierarchy Viewer You can determine layers and some performance stats of UI with this tool Hard to use but very effective!
  • 12. Use Less Objects, More Primitives Creating an object is extremely: EXPENSIVE! … but «primitive» is not! Using a 2 different integer array is more efficient than using object arrays like fooBar(int,int) badArray = new FooBar[] { new FooBar(5,8) , new FooBar(84,2) }; firstCoolArray = new int[] { 5, 84 }; secondCoolArray = new int[] { 8 , 2 };
  • 13. How to Search a 2D Array? Search first for row, then column TO DO for (int i = 0; i < foo.length ; i++) { for (int j = 0; j < foo.length ; j++) { process(foo[i,j]); } } NOT TO DO for (int i = 0; i < foo.length ; i++) { for (int j = 0; j < foo.length ; j++) { process(foo[j,i]); } }
  • 14. Use «Static» as Possible It is 15% - 20% faster! Static variables are initialized only once , at the start of the execution. And also use «static final» for your constants
  • 15. «Lint» Usage The lint tool checks your Android project source files for potential bugs and optimization improvements for correctness, security, performance, usability, accessibility, and internationalization. * http://developer.android.com/tools/debugging/improving-w-lint.html
  • 16. «Lint» Usage In Eclipse it is easy to use, just one click! In command line: «lint [flags] <project directory>» «lint myproject» «lint --check MissingPrefix myproject»
  • 17. Reusable Layouts It is commonly used for title bars, yes-no button panels etc. Very easy to implement: Create a layout and use it in another layout with «<include ../>» tag <include layout="@layout/titlebar"/>
  • 18. Do Your Hard-Work on Background Threads It is forbidden to make network processes in main thread, since Android 3.0 How about Instagram? When you finished writing some hashtags and pressed to send button, It had been posted just a while ago!
  • 19. View Holder for ListView Objects A ViewHolder object stores each of the component views inside the ListView object, so you can immediately access them without the need to look them up repeatedly. static class ViewHolder { TextView text; TextView timestamp; ImageView icon; } ViewHolder holder = new ViewHolder(); holder.icon = (ImageView) convertView.findViewById(R.id.listitem_image); holder.text = (TextView) convertView.findViewById(R.id.listitem_text); … Smooth!
  • 20. XML Drawables PNG’s, JPG’s and others are big sized and a hard work for mobile device. But creating an image with XML is very cheap and it is more efficient than you expected. Using a 400 kb background image or using an Xml drawable which has size of just 300 bytes?
  • 21. XML Drawables <?xml version="1.0" encoding="UTF-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <stroke android:width="3dp" android:color="#000000" /> <gradient android:endColor="#F5CD7A" android:startColor="#657892" android:angle="90" /> </shape>
  • 22. Handling Overdraws The most important part of performance. – If you ask me! Since Android 4.2, we can see overdraws in our devices. Overdraw is simply, drawing a pixel more than once. It’s notation is also simple: • No color: No overdraw • Blue: 1x overdraw (pixel is drawed 2 times) • Green: 2x overdraw • Light Red: 3x overdraw • Dark Red: 4x or more overdraw (ALERT!)
  • 24. • Acceptable red areas • Mostly blue and green • Optimized by Romain Guy - The God of Android Performance Optimization
  • 25. • JUST red areas • Whole screen is drawed more than 5 times • Probably haven’t checked for overdraws
  • 26. Handling Overdraws How to avoid? Actually its secret is written at the last one • thumbnail.setBackgroundColor(0x0); • android:windowBackground="@null" • If a view will not used anymore, don’t make its visibility «INVISIBLE», make it «GONE» • And use a simple design!
  • 27. Summary and Little Other Tips  Do use two parallel «int» arrays instead of array of objects (int,int)  Do use «primitive» instead of objects  Do use as possible as «static» methods  Do use «static final» for constants  Do use foreach instead of for  Do use as possible as Xml Drawables instead of images (jpg,png)  Don’t create unnecessary objects  Don’t allocate memory if you can work without it  Don’t use getters and setters inside the class  Don’t do your hard works on main thread and the most important one:  Don’t publish your app unless it doesn’t have performance problems!
  • 28. Torment Is Over, That’s All! Thanks for listening! O. Mert Şimşek /orhunmertsimsek mertsimsek.net