SlideShare une entreprise Scribd logo
1  sur  21
Télécharger pour lire hors ligne
Developer DayGoogle 2010
Thursday, September 16, 2010
High-performance Android apps
Tim Bray
Developer DayGoogle 2010
Thursday, September 16, 2010
Outline
• Why care?
• What is an ANR? Why do we see them?
• Quantifying responsiveness and “jank”
• Android SDK features for performance
• Numbers to know
• Storage and network issues
• Tools
• What to do?
Developer DayGoogle 2010
Thursday, September 16, 2010
“Jank”
• Chrome team's term for stalling the event loop,
i.e. not instantly responsive to input
• Eliminate by:
• Reacting to events quickly
• Don't hog the event loop (“main” / UI) thread!
• Getting back into the select() / epoll_wait()
call ASAP, so...
• … you can react to future events quickly
(touches, drags)
• Else...
Developer DayGoogle 2010
Thursday, September 16, 2010
Developer DayGoogle 2010
Thursday, September 16, 2010
ANR: “App Not Responding”
• Happens when:
• UI thread”) doesn't respond to input event in
5 seconds, or
• a BroadcastReceiver doesn't finish in 10
seconds
• Typically due to network or storage
operations on main thread
• But users complain about delays much less
than 5 seconds!
Developer DayGoogle 2010
Thursday, September 16, 2010
Some Nexus One Numbers
• ~0.04 ms: writing a byte on pipe process A->B, B->A
or reading simple /proc files from Dalvik
• ~0.12 ms: void/void Binder RPC call A->B, B->A
• ~5-25 ms: uncached flash reading a byte
• ~5-200+(!) ms: uncached flash writing tiny amount
• 16 ms: one frame of 60 fps video
• 100-200 ms: human perception of slow action
• 108/350/500/800 ms: ping over 3G. varies!
• ~1-6+ seconds: TCP setup + HTTP fetch of 6k via 3G
Developer DayGoogle 2010
Thursday, September 16, 2010
Writing to flash (yaffs2)
Developer DayGoogle 2010
Source: empirical samples over Google employee phones (Mar 2010)
• Create file, 512 byte write,
delete (ala sqlite .journal in
transaction)
• Flash is different than disks
you're likely used to: read,
write, erase, wear-leveling, GC
• Write performance is highly
variable!
Thursday, September 16, 2010
Sqlite Performance
• There’s no such thing as a cheap write
• Use indexes (see EXPLAIN & EXPLAIN
QUERY PLAN)
• For logging, consider file-append rather than
database-write
Developer DayGoogle 2010
Thursday, September 16, 2010
Lessons
• Writing to storage is slow
• Using the network is slow
• Always assume the worst; performance is
guaranteed to produce bad reviews and Market
ratings
Developer DayGoogle 2010
Thursday, September 16, 2010
Tools: asyncTask
Developer DayGoogle 2010
“AsyncTask enables proper
and easy use of the UI
thread. This class allows to
perform background
operations and publish
results on the UI thread
without having to manipulate
threads and/or handlers.”
Thursday, September 16, 2010
Tool: asyncTask
Developer DayGoogle 2010
private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> {
protected Long doInBackground(URL... urls) { // on some background thread
int count = urls.length; long totalSize = 0;
for (int i = 0; i < count; i++) {
totalSize += Downloader.downloadFile(urls[i]);
publishProgress((int) ((i / (float) count) * 100));
}
return totalSize;
}
protected void onProgressUpdate(Integer... progress) { // on UI thread!
setProgressPercent(progress[0]);
}
protected void onPostExecute(Long result) { // on UI thread!
showDialog("Downloaded " + result + " bytes");
}
}
new DownloadFilesTask().execute(url1, url2, url3); // call from UI thread!
Thursday, September 16, 2010
Tool: asyncTask
Developer DayGoogle 2010
private boolean handleWebSearchRequest(final ContentResolver cr) {
...
new AsyncTask<Void, Void, Void>() {
protected Void doInBackground(Void... unused) {
Browser.updateVisitedHistory(cr, newUrl, false);
Browser.addSearchUrl(cr, newUrl);
return null;
}
}.execute()
...
return true;
}
Thursday, September 16, 2010
asyncTask Details
• Must be called from a main thread
• rather, a thread with a Handler/Looper
• No nested calls!
• An activity process may exit before its
AsyncTask completes (user goes elsewhere,
low RAM, etc).
• If this is a problem, use IntentService
Developer DayGoogle 2010
Thursday, September 16, 2010
Tool: android.app.IntentService
• “IntentService is a base class for Services that
handle asynchronous requests (expressed as
Intents) on demand. Clients send requests
through startService(Intent) calls; the service is
started as needed, handles each Intent in turn
using a worker thread, and stops itself when it
runs out of work.”
• Intent happens in a Service, so Android tries
hard not to kill it
• Easy way to do use a Service
Developer DayGoogle 2010
Thursday, September 16, 2010
Calendar's use of IntentService
Developer DayGoogle 2010
public class DismissAllAlarmsService extends IntentService {
@Override public void onHandleIntent(Intent unusedIntent) {
ContentResolver resolver = getContentResolver();
...
resolver.update(uri, values, selection, null);
}
}
In AlertReceiver extends BroadcastReceiver, onReceive() (main thread)
Intent intent = new Intent(context, DismissAllAlarmsService.class);
context.startService(intent);
Thursday, September 16, 2010
UI Tips
• Disable UI elements immediately, before kicking off
your AsyncTask to finish the task
• Use an animation or ProgressDialog to show you’re
working
• One example strategy:
1. Immediately, disable UI elementes
2. Briefly, a spinner in the title bar
3. If more than 200msec, show a ProgressDialog
4. in AsyncTask onPostExecute, cancel alarm timer
Developer DayGoogle 2010
Thursday, September 16, 2010
What to do?
1. Design the simplest thing that could possible
work, where “could possibly work” excludes
doing network transactions on the UI thread.
Maybe it’ll be fast enough!
2. If it’s not fast enough, measure and find out
why.
3. Fix the biggest performance problems.
4. goto 2
Developer DayGoogle 2010
Thursday, September 16, 2010
Profiling Tools
• Traceview (for CPU-bound apps)
• dalvik.system.VMDebug#{start,stop}MethodTracing()
• adb shell am profile <PROCESS> start <FILE>
• adb shell am profile <PROCESS> stop
• Log.d() calls with a timestamp aren’t terrible
• Extreme profiling: Aggregate user profile data
Developer DayGoogle 2010
Thursday, September 16, 2010
Demo
• Profiling Tim’s “LifeSaver 2” application
Developer DayGoogle 2010
Thursday, September 16, 2010
Thank you!
Tim Bray, Developer Advocate
twbray@google.com android-developers.blogspot.com @AndroidDev
Developer DayGoogle 2010
Thursday, September 16, 2010

Contenu connexe

Similaire à Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)

Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011sullis
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium IntroNicholas Jansma
 
Using Modern Browser APIs to Improve the Performance of Your Web Applications
Using Modern Browser APIs to Improve the Performance of Your Web ApplicationsUsing Modern Browser APIs to Improve the Performance of Your Web Applications
Using Modern Browser APIs to Improve the Performance of Your Web ApplicationsNicholas Jansma
 
Recap of the google io 2017
Recap of the google io 2017Recap of the google io 2017
Recap of the google io 2017Karan Trehan
 
SumitK's mobile app dev using drupal as base ststem
SumitK's mobile app dev using drupal as base ststemSumitK's mobile app dev using drupal as base ststem
SumitK's mobile app dev using drupal as base ststemSumit Kataria
 
l1-reactnativeintroduction-160816150540.pdf
l1-reactnativeintroduction-160816150540.pdfl1-reactnativeintroduction-160816150540.pdf
l1-reactnativeintroduction-160816150540.pdfHương Trà Pé Xjnk
 
solution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptxsolution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptxGoogleDeveloperStude22
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptReact Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptKobkrit Viriyayudhakorn
 
Android 3.1 - Portland Code Camp 2011
Android 3.1 - Portland Code Camp 2011Android 3.1 - Portland Code Camp 2011
Android 3.1 - Portland Code Camp 2011sullis
 
Reliable mobile test automation
Reliable mobile test automationReliable mobile test automation
Reliable mobile test automationVishal Banthia
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App EngineVlad Filippov
 
Google's serverless journey: past to present
Google's serverless journey: past to presentGoogle's serverless journey: past to present
Google's serverless journey: past to presentwesley chun
 
An introduction to Titanium
An introduction to TitaniumAn introduction to Titanium
An introduction to TitaniumGraham Weldon
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performancedmethvin
 
Appcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium EcosystemAppcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium EcosystemBoydlee Pollentine
 
jQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPagesjQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPagesTeamstudio
 
Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15sullis
 
Using Azure Functions for Integration
Using Azure Functions for IntegrationUsing Azure Functions for Integration
Using Azure Functions for IntegrationBizTalk360
 
Meetup - Building by Composition - Samuel Jesus
Meetup - Building by Composition - Samuel JesusMeetup - Building by Composition - Samuel Jesus
Meetup - Building by Composition - Samuel JesusSamuel Jesus
 

Similaire à Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ) (20)

Android - Open Source Bridge 2011
Android - Open Source Bridge 2011Android - Open Source Bridge 2011
Android - Open Source Bridge 2011
 
Appcelerator Titanium Intro
Appcelerator Titanium IntroAppcelerator Titanium Intro
Appcelerator Titanium Intro
 
Using Modern Browser APIs to Improve the Performance of Your Web Applications
Using Modern Browser APIs to Improve the Performance of Your Web ApplicationsUsing Modern Browser APIs to Improve the Performance of Your Web Applications
Using Modern Browser APIs to Improve the Performance of Your Web Applications
 
Recap of the google io 2017
Recap of the google io 2017Recap of the google io 2017
Recap of the google io 2017
 
SumitK's mobile app dev using drupal as base ststem
SumitK's mobile app dev using drupal as base ststemSumitK's mobile app dev using drupal as base ststem
SumitK's mobile app dev using drupal as base ststem
 
l1-reactnativeintroduction-160816150540.pdf
l1-reactnativeintroduction-160816150540.pdfl1-reactnativeintroduction-160816150540.pdf
l1-reactnativeintroduction-160816150540.pdf
 
solution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptxsolution Challenge design and flutter day.pptx
solution Challenge design and flutter day.pptx
 
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScriptReact Native Introduction: Making Real iOS and Android Mobile App By JavaScript
React Native Introduction: Making Real iOS and Android Mobile App By JavaScript
 
Android 3.1 - Portland Code Camp 2011
Android 3.1 - Portland Code Camp 2011Android 3.1 - Portland Code Camp 2011
Android 3.1 - Portland Code Camp 2011
 
Reliable mobile test automation
Reliable mobile test automationReliable mobile test automation
Reliable mobile test automation
 
Web App Prototypes with Google App Engine
Web App Prototypes with Google App EngineWeb App Prototypes with Google App Engine
Web App Prototypes with Google App Engine
 
Google's serverless journey: past to present
Google's serverless journey: past to presentGoogle's serverless journey: past to present
Google's serverless journey: past to present
 
An introduction to Titanium
An introduction to TitaniumAn introduction to Titanium
An introduction to Titanium
 
jQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web PerformancejQuery Conference San Diego 2014 - Web Performance
jQuery Conference San Diego 2014 - Web Performance
 
Appcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium EcosystemAppcelerator Titanium - An Introduction to the Titanium Ecosystem
Appcelerator Titanium - An Introduction to the Titanium Ecosystem
 
Unit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.pptUnit I- ANDROID OVERVIEW.ppt
Unit I- ANDROID OVERVIEW.ppt
 
jQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPagesjQuery: The World's Most Popular JavaScript Library Comes to XPages
jQuery: The World's Most Popular JavaScript Library Comes to XPages
 
Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15Android 3.0 Portland Java User Group 2011-03-15
Android 3.0 Portland Java User Group 2011-03-15
 
Using Azure Functions for Integration
Using Azure Functions for IntegrationUsing Azure Functions for Integration
Using Azure Functions for Integration
 
Meetup - Building by Composition - Samuel Jesus
Meetup - Building by Composition - Samuel JesusMeetup - Building by Composition - Samuel Jesus
Meetup - Building by Composition - Samuel Jesus
 

Plus de Google Developer Relations Team

Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)Google Developer Relations Team
 
Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...
Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...
Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...Google Developer Relations Team
 
Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...
Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...
Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...Google Developer Relations Team
 
Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...
Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...
Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...Google Developer Relations Team
 
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)Google Developer Relations Team
 
Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)
Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)
Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)Google Developer Relations Team
 
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)Google Developer Relations Team
 
Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)
Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)
Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)Google Developer Relations Team
 
Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)
Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)
Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)Google Developer Relations Team
 
Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...
Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...
Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...Google Developer Relations Team
 

Plus de Google Developer Relations Team (10)

Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
Google Developer Day 2010 Japan: 音声入力 API for Android (アレックス グランスタイン, 小西 祐介)
 
Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...
Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...
Google Developer Day 2010 Japan: 「App Engine 開発者コミュニティ「appengine ja night」とフレ...
 
Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...
Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...
Google Developer Day 2010 Japan: Part 1: Google App Engine for Business の概要 P...
 
Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...
Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...
Google Developer Day 2010 Japan: Google Chrome の Developer Tools (ミカイル ナガノフ, ...
 
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
Google Developer DAy 2010 Japan: HTML5 についての最新情報 (マイク スミス)
 
Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)
Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)
Google Developer Day 2010 Japan: 新 SocialWeb: 全てはオープンスタンダードの元に (ティモシー ジョーダン)
 
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
Google Developer Day 2010 Japan: プログラミング言語 Go (鵜飼 文敏)
 
Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)
Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)
Google Developer Day 2010 Japan: HTML5 とウェブサイトデザイン (矢倉 眞隆)
 
Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)
Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)
Google Developer Day 2010 Japan: Android でリアルタイムゲームを開発する方法: リベンジ (クリス プルエット)
 
Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...
Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...
Google Developer Day 2010 Japan: マーケットライセンシングを使って Android アプリケーションを守るには (トニー ...
 

Dernier

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
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
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelDeepika Singh
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Bhuvaneswari Subramani
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
"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
 

Dernier (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+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...
 
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
 
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
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
"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 ...
 

Google Developer Day 2010 Japan: 高性能な Android アプリを作るには (ティム ブレイ)

  • 2. High-performance Android apps Tim Bray Developer DayGoogle 2010 Thursday, September 16, 2010
  • 3. Outline • Why care? • What is an ANR? Why do we see them? • Quantifying responsiveness and “jank” • Android SDK features for performance • Numbers to know • Storage and network issues • Tools • What to do? Developer DayGoogle 2010 Thursday, September 16, 2010
  • 4. “Jank” • Chrome team's term for stalling the event loop, i.e. not instantly responsive to input • Eliminate by: • Reacting to events quickly • Don't hog the event loop (“main” / UI) thread! • Getting back into the select() / epoll_wait() call ASAP, so... • … you can react to future events quickly (touches, drags) • Else... Developer DayGoogle 2010 Thursday, September 16, 2010
  • 6. ANR: “App Not Responding” • Happens when: • UI thread”) doesn't respond to input event in 5 seconds, or • a BroadcastReceiver doesn't finish in 10 seconds • Typically due to network or storage operations on main thread • But users complain about delays much less than 5 seconds! Developer DayGoogle 2010 Thursday, September 16, 2010
  • 7. Some Nexus One Numbers • ~0.04 ms: writing a byte on pipe process A->B, B->A or reading simple /proc files from Dalvik • ~0.12 ms: void/void Binder RPC call A->B, B->A • ~5-25 ms: uncached flash reading a byte • ~5-200+(!) ms: uncached flash writing tiny amount • 16 ms: one frame of 60 fps video • 100-200 ms: human perception of slow action • 108/350/500/800 ms: ping over 3G. varies! • ~1-6+ seconds: TCP setup + HTTP fetch of 6k via 3G Developer DayGoogle 2010 Thursday, September 16, 2010
  • 8. Writing to flash (yaffs2) Developer DayGoogle 2010 Source: empirical samples over Google employee phones (Mar 2010) • Create file, 512 byte write, delete (ala sqlite .journal in transaction) • Flash is different than disks you're likely used to: read, write, erase, wear-leveling, GC • Write performance is highly variable! Thursday, September 16, 2010
  • 9. Sqlite Performance • There’s no such thing as a cheap write • Use indexes (see EXPLAIN & EXPLAIN QUERY PLAN) • For logging, consider file-append rather than database-write Developer DayGoogle 2010 Thursday, September 16, 2010
  • 10. Lessons • Writing to storage is slow • Using the network is slow • Always assume the worst; performance is guaranteed to produce bad reviews and Market ratings Developer DayGoogle 2010 Thursday, September 16, 2010
  • 11. Tools: asyncTask Developer DayGoogle 2010 “AsyncTask enables proper and easy use of the UI thread. This class allows to perform background operations and publish results on the UI thread without having to manipulate threads and/or handlers.” Thursday, September 16, 2010
  • 12. Tool: asyncTask Developer DayGoogle 2010 private class DownloadFilesTask extends AsyncTask<URL, Integer, Long> { protected Long doInBackground(URL... urls) { // on some background thread int count = urls.length; long totalSize = 0; for (int i = 0; i < count; i++) { totalSize += Downloader.downloadFile(urls[i]); publishProgress((int) ((i / (float) count) * 100)); } return totalSize; } protected void onProgressUpdate(Integer... progress) { // on UI thread! setProgressPercent(progress[0]); } protected void onPostExecute(Long result) { // on UI thread! showDialog("Downloaded " + result + " bytes"); } } new DownloadFilesTask().execute(url1, url2, url3); // call from UI thread! Thursday, September 16, 2010
  • 13. Tool: asyncTask Developer DayGoogle 2010 private boolean handleWebSearchRequest(final ContentResolver cr) { ... new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void... unused) { Browser.updateVisitedHistory(cr, newUrl, false); Browser.addSearchUrl(cr, newUrl); return null; } }.execute() ... return true; } Thursday, September 16, 2010
  • 14. asyncTask Details • Must be called from a main thread • rather, a thread with a Handler/Looper • No nested calls! • An activity process may exit before its AsyncTask completes (user goes elsewhere, low RAM, etc). • If this is a problem, use IntentService Developer DayGoogle 2010 Thursday, September 16, 2010
  • 15. Tool: android.app.IntentService • “IntentService is a base class for Services that handle asynchronous requests (expressed as Intents) on demand. Clients send requests through startService(Intent) calls; the service is started as needed, handles each Intent in turn using a worker thread, and stops itself when it runs out of work.” • Intent happens in a Service, so Android tries hard not to kill it • Easy way to do use a Service Developer DayGoogle 2010 Thursday, September 16, 2010
  • 16. Calendar's use of IntentService Developer DayGoogle 2010 public class DismissAllAlarmsService extends IntentService { @Override public void onHandleIntent(Intent unusedIntent) { ContentResolver resolver = getContentResolver(); ... resolver.update(uri, values, selection, null); } } In AlertReceiver extends BroadcastReceiver, onReceive() (main thread) Intent intent = new Intent(context, DismissAllAlarmsService.class); context.startService(intent); Thursday, September 16, 2010
  • 17. UI Tips • Disable UI elements immediately, before kicking off your AsyncTask to finish the task • Use an animation or ProgressDialog to show you’re working • One example strategy: 1. Immediately, disable UI elementes 2. Briefly, a spinner in the title bar 3. If more than 200msec, show a ProgressDialog 4. in AsyncTask onPostExecute, cancel alarm timer Developer DayGoogle 2010 Thursday, September 16, 2010
  • 18. What to do? 1. Design the simplest thing that could possible work, where “could possibly work” excludes doing network transactions on the UI thread. Maybe it’ll be fast enough! 2. If it’s not fast enough, measure and find out why. 3. Fix the biggest performance problems. 4. goto 2 Developer DayGoogle 2010 Thursday, September 16, 2010
  • 19. Profiling Tools • Traceview (for CPU-bound apps) • dalvik.system.VMDebug#{start,stop}MethodTracing() • adb shell am profile <PROCESS> start <FILE> • adb shell am profile <PROCESS> stop • Log.d() calls with a timestamp aren’t terrible • Extreme profiling: Aggregate user profile data Developer DayGoogle 2010 Thursday, September 16, 2010
  • 20. Demo • Profiling Tim’s “LifeSaver 2” application Developer DayGoogle 2010 Thursday, September 16, 2010
  • 21. Thank you! Tim Bray, Developer Advocate twbray@google.com android-developers.blogspot.com @AndroidDev Developer DayGoogle 2010 Thursday, September 16, 2010