Download presentation
Presentation is loading. Please wait.
Published byHorace McDaniel Modified over 9 years ago
1
Mobile Application Optimization
2
Sanath Nandasiri Programmer.(Not a singer) (Exilesoft)
3
Outline Why we need optimization. Performance tuning life cycle. Networking Optimizations. Memory Optimizations. UI Optimization. Reduce Size of APK.
4
Why we need optimization Pretty simple.
6
Performance Tuning You might have good reason to optimize
8
Networking Optimizations Network handling. Network Request. Batching background work. Battery.
9
Network handling Respect your user
10
Network radio
11
Network Request How to make good request.
12
Type of Network request.
13
Server pulling is bad? It drains Battery so past
14
Server push is better ( Using GCM)
15
Good way of handling the server pulling
16
Try to batching when ever possible.
17
Also prefetching data for future use.
18
Batching background work Sync later.
19
Use alarm manager Exact Alarm Inexact Alarm
20
How to set
21
Using Sync Adapters.
22
GcmNetworkManager (Pre L)
23
JobScheduler API (L).
24
Battery May be your major concern.
25
Measure battery consumption. Use battery historian tool. https://github.com/google/battery-historian. https://github.com/google/battery-historian adb shell dumpsys batterystats --reset adb shell dumpsys batterystats> report.txt historian.py report.txt> raport.html
26
Demo Use battery historian tool
27
Memory Optimizations. HashMap. AutoBoxing. SparseArrayFamily. Enums. Iterator or index. BitMaps. Memory Leaks.
28
HashMap
30
ArrayMaps
31
ArrayMaps search
32
ArrayMap search
33
ArrayMap allocation vs HashMap allocation
34
Where to use ArrayMap
35
AutoBoxing
36
What is autoboxing
37
Primitive vs Generics
38
Problem with HashMap and ArrayMap
39
SparseArray Family
40
No autoboxing
41
Enums. Enums sucks.
42
Cost of Enums “Enums often require more than twice as much memory as static constants.You should strictly avoid using enums on Android” Google
43
Integer vs Enums 20+ byte for each 12-16 byte array This is 13x more than integer version
44
Using Integer constant with @IntDef
45
Stop using Enums. if already used, try to setup proguard
46
Iterator or index.
47
Methodcode for IndexInt size = list.size(); for(int i = 0 ;I < size ; i++){ Object o = list.get(i) } Iteratorfor(Iterator it = list.iterator(); it.hasNext();){ Object o = it.next(); } for simplefor(Object o : list){ … } Method for Iterate a list
48
Stats of all methods
49
Bitmaps. Memory hungry
50
Bitmap need continues memory blocks
51
Select smaller pixel format
52
Scale the Bitmap
53
Reuse Bitmap
54
Good to use libs
55
Memory Leaks Avoid, May cause to crash or freeze.
56
Memory leaks GC not prevent memory leaks Reference to an unused object preventing GC. Reference to Activity (Context) View Drawables Etc…
58
Object in Heap Shallow Heap How large this object is. (size in byte) Retained Heap Total memory freed by removing particular object.
59
How to detect memory leaks Using MAT (Memory Analyzer Tool) It uses Dominator tree to calculate retained heap.
60
Dominator tree Dominator : closest object on every path to node
61
Demo use MAT Memory Analysis for Android Applications
62
UI Optimization Beauty need more care. Hierarchy Viewer Walkthrough
63
Hierarchy Viewer to see UI view hierarchy
64
Avoid much deeper layout hierarchy.
65
Custom View for more complex view
66
Lint Use Lint, to have a hint. Improving Your Code with lint
67
How lint works
68
Lint report
69
Demo Use Lint tool.
70
Reduce Size of APK To save users data. Putting Your APKs on Diet
71
Steps Run Proguard Use Lint extensively Be opinionated about resources Use hdpi, xhdpi and xxhdpi Minimize resources configurations Compress images Code reuse
72
Q & A More help Android Performance Patterns sanathe06@gmail.com 0713429751
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.