24
(Code for Responsiveness) Thinking of CPU & Memory

Thinking of CPU and Memory (1.0)

Embed Size (px)

Citation preview

Page 1: Thinking of CPU and Memory (1.0)

(Code for Responsiveness)

Thinking of CPU & Memory

Page 2: Thinking of CPU and Memory (1.0)

Terminado!

La aplicación funciona

Page 3: Thinking of CPU and Memory (1.0)

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 (1.0)

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 (1.0)

Cada vez somos más vagos exigentes

Page 6: Thinking of CPU and Memory (1.0)

El concepto

Caso clásico:1. Descargas datos (cache de Strings)2. Parseas (cache de objetos)3. Descargas más datos: imágenes, etc (LruCache)4. Cargas en memoria (mantenerlos en memoria)5. Los muestras en pantalla

Page 7: Thinking of CPU and Memory (1.0)

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 (1.0)

Como?

● Las splash-screens són malignas● No hacer trabajos en el UI Thread● No bloquear la UI (ProgressDialogs...)● No descargar los mismos datos 2 veces

○ nos centraremos en este punto

Page 9: Thinking of CPU and Memory (1.0)

Strict Mode

.penaltyLog()

.penaltyDeath()

Page 10: Thinking of CPU and Memory (1.0)

Red(Enemigo nº 1)

Page 11: Thinking of CPU and Memory (1.0)

DDMS (Network Statistics)

Red (Análisis)

Page 12: Thinking of CPU and Memory (1.0)

12s -> 0.4s (wifi mala, móvil bueno)

Red (tip 1)

Page 13: Thinking of CPU and Memory (1.0)

LruCache+DiskLruCache

● Displaying Bitmaps Efficiently (Android Developers)

● https://github.com/koush/UrlImageViewHelper○ No gestiona bien vistas recicladas (aún)

Red (tip 2)

Page 14: Thinking of CPU and Memory (1.0)

CPUNo todos los móviles son de 4 núcleos

Page 15: Thinking of CPU and Memory (1.0)

Traceview (code y DDMS)

CPU (Análisis)

Page 16: Thinking of CPU and Memory (1.0)

Guardar i leer object

7s -> 0.8s (móvil malo)

Page 17: Thinking of CPU and Memory (1.0)

Mostrar datosviejos siempre

Page 18: Thinking of CPU and Memory (1.0)

Memória RAMSi no compartes, te echan

Page 19: Thinking of CPU and Memory (1.0)

$ adb shell procrank

Mantener la aplicación en memoria (Análisis)

Page 20: Thinking of CPU and Memory (1.0)

Mantener la aplicación en memoria (Tip)

Page 21: Thinking of CPU and Memory (1.0)

● 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 22: Thinking of CPU and Memory (1.0)

● 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 23: Thinking of CPU and Memory (1.0)

"Donald Knuth"

"La optimización prematura es la raíz de todos los males"

Page 24: Thinking of CPU and Memory (1.0)

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

twitter: @oriolj+Oriol Jiménez