thinking of cpu and memory (2.0)
DESCRIPTION
charla del droidcon españa 2012TRANSCRIPT
![Page 1: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/1.jpg)
(Code for Responsiveness)
Thinking of CPU & Memory
![Page 2: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/2.jpg)
Terminado!
La aplicación funciona
![Page 3: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/3.jpg)
Por que?
1 de cada 4 personas abandona una web que tarda más de 4 segundos en cargar
![Page 4: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/4.jpg)
Por que?
● Amazon: +100ms = -1% ventas● Google: un incremento de 0.4 segundos a
0.9 segundos en carga de pàgina equivale a un descenso de tràfico e ingresos del 20%
● Apps móviles?
![Page 5: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/5.jpg)
Cada vez somos más vagos exigentes
![Page 6: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/6.jpg)
El concepto
Caso clásico:1. Descargas datos2. Parseas3. Descargas más datos: imágenes, etc4. Cargas en memoria5. Los muestras en pantalla
![Page 7: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/7.jpg)
Don't be a Java Hero
"Tengo la impresión de que Java fue diseñado para hacer que fuera difícil escribir mal código, mientras que Python está diseñado para hacer
que sea sencillo escribir buen código."– Magnus Lycka
![Page 8: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/8.jpg)
Como?
● Compila contra el último SDK (hardware accel, p.ej)● Las splash-screens són malignas● No hacer trabajos en el UI Thread● No bloquear la UI (ProgressDialogs...)● GetView "ligeros"● No descargar los mismos datos 2 veces
○ punto 1 a tratar● Luchar por los 60fps
○ punto 2 a tratar
![Page 9: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/9.jpg)
Velocidad
![Page 10: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/10.jpg)
Strict Mode
.penaltyLog()
.penaltyDeath()
![Page 11: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/11.jpg)
Red(Enemigo nº 1)
![Page 12: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/12.jpg)
DDMS (Network Statistics)
Red (Análisis)
![Page 13: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/13.jpg)
12s -> 0.4s (wifi mala, móvil bueno)
Red (tip 1) - cache de string
![Page 14: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/14.jpg)
LruCache+DiskLruCache
● Displaying Bitmaps Efficiently (Android Developers)
● https://github.com/koush/UrlImageViewHelper○ No gestiona bien vistas recicladas (aún)
Red (tip 2) - cache de bitmaps
![Page 15: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/15.jpg)
CPUNo todos los móviles son de 4 núcleos
![Page 16: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/16.jpg)
Traceview (code y DDMS)
CPU (Análisis)
![Page 17: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/17.jpg)
Guardar y leer object
7s -> 0.8s (móvil malo)
![Page 18: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/18.jpg)
Mostrar datosviejos siempre
Ejemplo: Google+Mal-ejemplo: facebook
![Page 19: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/19.jpg)
Memória RAMSi no compartes, te echan
![Page 20: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/20.jpg)
$ adb shell procrank
Mantener la aplicación en memoria (Análisis)
![Page 21: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/21.jpg)
Mantener la aplicación en memoria (Tip)
![Page 22: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/22.jpg)
SmoothnessLos preciados 60 fps
![Page 23: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/23.jpg)
Smoothness
● Sección "robada" de:○ http://www.curious-creature.org/docs/android-performance-case-study-1.html
○ http://www.curious-creature.org/2012/12/06/android-performance-in-practice/
● Profile GPU rendering (4.1)● GPU Overdraw (4.2)● Systrace (4.1)● Hierarchy Viewer
![Page 24: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/24.jpg)
Profile GPU Rendering
● profile first 128 frames of every window● Activar en dispositivo (dev. options)● adb shell dumpsys glxinfo com.test.app● se necesitan <16ms por frame
![Page 25: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/25.jpg)
Systrace
● Activar en dispositivo (dev. options)● tools/systrace/systrace.py (5 seconds by default)
![Page 26: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/26.jpg)
GPU OverDraw
● Como recomendación, podemos pintar cada pixel un máximo de 3 veces
● 9-patch for backgrounds
![Page 27: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/27.jpg)
Hierarchy Viewer
![Page 28: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/28.jpg)
● Heap dump (memoria por objetos)● Eclipse MAT (memoria por objetos)● PerfMon (memoria, cpu, red en float)● Usage Timelines Pro (cpu, memoria)● traceview (cpu)
Otras utilidades
![Page 29: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/29.jpg)
● Guardar un long en Application y mostrar un Toast con la diferencia al mostrar los primeros datos
● Enviar por analytics velocidades de boot
Detectar regresiones
![Page 30: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/30.jpg)
"Donald Knuth"
"La optimización prematura es la raíz de todos los males"
![Page 31: Thinking of CPU and Memory (2.0)](https://reader033.vdocument.in/reader033/viewer/2022052905/5585a433d8b42a6c1a8b4913/html5/thumbnails/31.jpg)
Reférencias● Google I/O 2012 - Doing More With less: Beign a Good
Android Citizen● Designing for Performance (developer.android.com)● "Displaying Bitmaps Efficiently" Android Developers● http://www.curious-creature.org/docs/android-performance-
case-study-1.html● http://www.curious-creature.org/2012/12/06/android-
performance-in-practice/
twitter: @oriolj+Oriol Jiménez