SlideShare ist ein Scribd-Unternehmen logo
1 von 28
Tran Vu Tat Binh
I’ve done all kind of micro-optimizations, use good
algorithms, choose the right data structures but still
got serious performance issues in my mobile apps.
Our online game took about 10
minutes to download 25 MB resources
using 3G in the old version
Performance issues?
 The overall application runs slow.
 The application makes other
applications on phone run slower (yes, it
can)
 Users feel the application slow.
 Be strict: it’s also performance issue if
we can do much better but we don’t
Some interesting points
 Number of threads
 Organizing threads
 Multi-threading and network
 Mobile network under the hood
Number of threads
 Using too many threads
After launch Rush hour
Number of threads
 Using too many threads:
 Overhead
 Hard to control
 Less time for each thread
 Concurrency
Number of threads
 Using too few threads:
 Not take advantage of system resources
 Not so responsive
Number of threads
So how many?
Flexible and should not be a fixed
number, see the next “Organizing
threads” for more details.
Organizing threads
 Usually, there are 3 kinds of task
 Blocking UI task
 Updater task
 Lazy media task
Organizing threads
 Blocking UI task
○ When there are no other data
on screen
○ When user definitely have to
wait for updated data only
Should be a single thread with
high priority since user can not
proceed if task is not done.
Organizing threads
 Updater task
○ Updating / refreshing
○ Loading more
○ User can still interact with
existed data on screen
○ Can move to other screen
without finishing task
Should be a thread pool
(suggest size 2-4)
Organizing threads
 Lazy media task
○ Thumbnails for existed data
○ A list/grid of images
Should be 2 thread pools: one
for downloading and one for
decoding
Organizing threads
 Lazy media task (con.)
 Usually most heavy task  focus optimizing
 Why separating into downloading and
decoding
○ Images might be in local cache already and
decoding usually much faster than
downloading, so don’t let downloading slow
down the progress
○ Decoding pool size should be based on CPU
cores
○ Downloading pool size should be based on
network status
Organizing threads
 Decoding pool size
NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors();
mDecodeThreadPool = new ThreadPoolExecutor(NUMBER_OF_CORES,
NUMBER_OF_CORES, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT,
mDecodeWorkQueue);
Organizing threads
 Downloading pool size
 Normal:
○ Fixed size (may be 8 like in some tutorials)
 More optimized:
○ 2G – size 4
○ 3G – size 8
○ 4G – size 16 (or more)
○ WIFI – size 8
 Much more optimized:
○ Based on network speed, increasing size if
can still download faster, decreasing size if
still not slower, until get the best size.
Organizing threads
 Why variable size is better choice:
2G pool size 2
2G pool size 4
2G pool size 8
Organizing threads
 Why variable size is better choice:
3G pool size 4 3G pool size 8
3G pool size 24
Organizing threads
 Facts:
 Each connection has a limited bandwidth
 The phone’s network connection has a
overall limited bandwidth
 There are network latency causing “gaps”
while downloading
Organizing threads
 Downloading pool size
 Too small size
○ Waste network bandwidth
○ Drain battery life if using mobile network
○ Slow
 Too large size
○ Take more time to show individual image (not
overall images on screen)  users feel slow
○ TCP congestion control
○ Slower to start downloading new images when
scrolling
Variable size based on network status is good
choice but need more time to implement
Organizing threads
 Conclusion:
 Blocking UI task – 1 thread
 Updater task – 1 thread pool size 2 - 4
 Lazy media task – 2 thread pools
○ 1 thread pool for decoding size = available cores
○ 1 thread pool for downloading size based on
network status
Mobile network under the hood
 Online applications like messenger,
news reader, social app or online
game… some got serious issues when
using mobile network
○ Battery drain
○ Slow response
Mobile network
 Typical 3G wireless radio state machine (source)
Mobile network
 Messenger application
○ Small data message
○ Transferring more
frequently
○ No fixed schedule
Mobile network
 Online game
○ Small data message
○ Transferring much more
frequently
○ Usually fixed schedule
○ Responsiveness is
importance
Mobile network
 Social app
 News reader
 Photo sharing
 Music app
…
Mobile network
 Optimize data to transfer (as always)
 Batch operation
 Prefetch
 When receive, if need to transmit then
do quick
 If possible, do at the same time with
other apps
Q&A
Thank you!

Weitere ähnliche Inhalte

Mehr von GameLandVN

OGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny BustersOGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny Busters
GameLandVN
 
OGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overviewOGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overview
GameLandVN
 
OGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d modelsOGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d models
GameLandVN
 
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to MobileOGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
GameLandVN
 
OGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototypeOGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototype
GameLandVN
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
GameLandVN
 
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile gameOGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
GameLandVN
 
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
GameLandVN
 

Mehr von GameLandVN (20)

Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
Mobile Game Asia 2015 Ho Chi Minh City: Building a sustainable eSports ecosys...
 
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
Mobile Game Asia 2015 Ho Chi Minh City: An overview of the mobile game market...
 
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
Mobile Game Asia 2015 Ho Chi Minh City: Monetization strategies in Southeast ...
 
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video adsMobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
Mobile Game Asia 2015 Ho Chi Minh City: Rewarded video ads
 
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in VietnamMobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
Mobile Game Asia 2015 Ho Chi Minh City: The role of a game publisher in Vietnam
 
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetizationMobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
Mobile Game Asia 2015 Ho Chi Minh City: Predictive monetization
 
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creationMobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
Mobile Game Asia 2015 Ho Chi Minh City: The roadmap of IP creation
 
Cloud Powered Mobile Apps with Azure
Cloud Powered Mobile Apps with AzureCloud Powered Mobile Apps with Azure
Cloud Powered Mobile Apps with Azure
 
Windows app & Microsoft's support
Windows app & Microsoft's supportWindows app & Microsoft's support
Windows app & Microsoft's support
 
Kinh nghiệm phát triển Captain Strike
Kinh nghiệm phát triển Captain StrikeKinh nghiệm phát triển Captain Strike
Kinh nghiệm phát triển Captain Strike
 
Microsoft BizSpark
Microsoft BizSparkMicrosoft BizSpark
Microsoft BizSpark
 
Microsoft Azure Introduction
Microsoft Azure IntroductionMicrosoft Azure Introduction
Microsoft Azure Introduction
 
OGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny BustersOGDC 2014: Animation workflow with Spine in Tiny Busters
OGDC 2014: Animation workflow with Spine in Tiny Busters
 
OGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overviewOGDC 2014: Vietnam Smartphone game market 2013 overview
OGDC 2014: Vietnam Smartphone game market 2013 overview
 
OGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d modelsOGDC 2014: Speed up and make quality for your 3d models
OGDC 2014: Speed up and make quality for your 3d models
 
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to MobileOGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
OGDC 2014: Sky Garden Mobile conceptualization: From PC to Mobile
 
OGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototypeOGDC 2014: One-Man Studio: How to make a game prototype
OGDC 2014: One-Man Studio: How to make a game prototype
 
OGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dxOGDC 2014: Program farmery by cocos2dx
OGDC 2014: Program farmery by cocos2dx
 
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile gameOGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
OGDC 2014: Optimize or Die: Key disciplines to optimize your mobile game
 
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
OGDC 2014: Tips and Tricks for seasonal events and community building in Drag...
 

Kürzlich hochgeladen

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
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
Safe Software
 
+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...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Kürzlich hochgeladen (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
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
 
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
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
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
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
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
 
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​
 
+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...
 
"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 ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
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...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Vietnam Mobile Day 2013: For Higher Performance Mobile Applications

  • 1. Tran Vu Tat Binh
  • 2. I’ve done all kind of micro-optimizations, use good algorithms, choose the right data structures but still got serious performance issues in my mobile apps. Our online game took about 10 minutes to download 25 MB resources using 3G in the old version
  • 3. Performance issues?  The overall application runs slow.  The application makes other applications on phone run slower (yes, it can)  Users feel the application slow.  Be strict: it’s also performance issue if we can do much better but we don’t
  • 4. Some interesting points  Number of threads  Organizing threads  Multi-threading and network  Mobile network under the hood
  • 5. Number of threads  Using too many threads After launch Rush hour
  • 6. Number of threads  Using too many threads:  Overhead  Hard to control  Less time for each thread  Concurrency
  • 7. Number of threads  Using too few threads:  Not take advantage of system resources  Not so responsive
  • 8. Number of threads So how many? Flexible and should not be a fixed number, see the next “Organizing threads” for more details.
  • 9. Organizing threads  Usually, there are 3 kinds of task  Blocking UI task  Updater task  Lazy media task
  • 10. Organizing threads  Blocking UI task ○ When there are no other data on screen ○ When user definitely have to wait for updated data only Should be a single thread with high priority since user can not proceed if task is not done.
  • 11. Organizing threads  Updater task ○ Updating / refreshing ○ Loading more ○ User can still interact with existed data on screen ○ Can move to other screen without finishing task Should be a thread pool (suggest size 2-4)
  • 12. Organizing threads  Lazy media task ○ Thumbnails for existed data ○ A list/grid of images Should be 2 thread pools: one for downloading and one for decoding
  • 13. Organizing threads  Lazy media task (con.)  Usually most heavy task  focus optimizing  Why separating into downloading and decoding ○ Images might be in local cache already and decoding usually much faster than downloading, so don’t let downloading slow down the progress ○ Decoding pool size should be based on CPU cores ○ Downloading pool size should be based on network status
  • 14. Organizing threads  Decoding pool size NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors(); mDecodeThreadPool = new ThreadPoolExecutor(NUMBER_OF_CORES, NUMBER_OF_CORES, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, mDecodeWorkQueue);
  • 15. Organizing threads  Downloading pool size  Normal: ○ Fixed size (may be 8 like in some tutorials)  More optimized: ○ 2G – size 4 ○ 3G – size 8 ○ 4G – size 16 (or more) ○ WIFI – size 8  Much more optimized: ○ Based on network speed, increasing size if can still download faster, decreasing size if still not slower, until get the best size.
  • 16. Organizing threads  Why variable size is better choice: 2G pool size 2 2G pool size 4 2G pool size 8
  • 17. Organizing threads  Why variable size is better choice: 3G pool size 4 3G pool size 8 3G pool size 24
  • 18. Organizing threads  Facts:  Each connection has a limited bandwidth  The phone’s network connection has a overall limited bandwidth  There are network latency causing “gaps” while downloading
  • 19. Organizing threads  Downloading pool size  Too small size ○ Waste network bandwidth ○ Drain battery life if using mobile network ○ Slow  Too large size ○ Take more time to show individual image (not overall images on screen)  users feel slow ○ TCP congestion control ○ Slower to start downloading new images when scrolling Variable size based on network status is good choice but need more time to implement
  • 20. Organizing threads  Conclusion:  Blocking UI task – 1 thread  Updater task – 1 thread pool size 2 - 4  Lazy media task – 2 thread pools ○ 1 thread pool for decoding size = available cores ○ 1 thread pool for downloading size based on network status
  • 21. Mobile network under the hood  Online applications like messenger, news reader, social app or online game… some got serious issues when using mobile network ○ Battery drain ○ Slow response
  • 22. Mobile network  Typical 3G wireless radio state machine (source)
  • 23. Mobile network  Messenger application ○ Small data message ○ Transferring more frequently ○ No fixed schedule
  • 24. Mobile network  Online game ○ Small data message ○ Transferring much more frequently ○ Usually fixed schedule ○ Responsiveness is importance
  • 25. Mobile network  Social app  News reader  Photo sharing  Music app …
  • 26. Mobile network  Optimize data to transfer (as always)  Batch operation  Prefetch  When receive, if need to transmit then do quick  If possible, do at the same time with other apps
  • 27. Q&A