Collections of all kinds of tricks of improving performance
Memory Performance Tools:
Overall Performance Tools:
The Performance Lifecyle
Gather:收集数据
Insight:分析数据
Action:解决问题
Ui Layer
优化布局文件
tools: hierarchy viewer
减少布局层次,保持层次扁平化
删除不必要的组件
查看 GPU 过度渲染
tools: gpu overdraw display
利用 cliprect
取消设置背景
GPU 显示配置文件
使用 GPU 渲染 View
自定义 View 覆盖 hasOverlappingRendering() 并返回 false
Avoiding allocations in onDraw()
Custom View
Smaller Pixel Formats
Pre-scaling Bitmaps
Re-using Bitmaps
Memory Layer
避免 GC 操作过于频繁
tools: Memory Monitor / Heap and Allocation Tracker
reason 1: memory churn
reason 2: 瞬间产生大量的对象占用了内存区域,导致各种类型的 GC
避免 Memory Leak
tools: Heap tool / Allocation Track
method of checking leak: observed activity(use heap tool to capture current memory state) -> blank activity(call gc() actively , then use heap tool to capture current memory state, now it should not have previous activity's memory footprint. If not, then leak...)
method of finding leaked memory footprint: blank activity(use tool of Allocation Track , begin track) -> observed activity -> blank activity(end track, then find the objects still alive)
do not leak views
使用 Object Pools
使用 LRU Cache
Battery Layer
tools: Battery Historian Tool / JobScheduler API (since level 20)
我们应该尽量减少唤醒屏幕的次数与持续的时间,使用WakeLock来处理唤醒的问题,能够正确执行唤醒操作并根据设定及时关闭操作进入睡眠状态
某些非必须马上执行的操作,例如上传歌曲,图片处理等,可以等到设备处于充电状态或者电量充足的时候才进行
触发网络请求的操作,每次都会保持无线信号持续一段时间,我们可以把零散的网络请求打包进行一次操作,避免过多的无线信号引起的电量消耗
Network Layer
Bussiness Layer
Code Layer
基于场景选择合适的数据结构
colors.xml 不要采用业务来命名,直接使用颜色命名
优化时的大概分析思路
Useful Resources