Android performance: An overview
yuli.kamakura
Engineering Productivity
From app code all the way down to the kernel
2022
Agenda
硬件的视角看性能优化
x86
ARM
更长的时间范围来看
硬件的视角看性能优化
更长的时间范围来看
未来?
Bytedance Inc. 移动端性能优化的现状
by 抖音 Android 基础技术
by 今日头条 Android 平台业务
Bytedance Inc. 进一步遇到的问题
线上疑难问题如何归因和优化
偶现的问题
线下如何更早发现问题
挖掘新的优化点?
移动操作系统和硬件厂商的性能优化
Apple
移动操作系统和硬件厂商的性能优化
Android
2014
2016
2018
2015
2017
2019
ZRAM & KSM
RenderScript with GPU accelerate
HWUI
Android Rutime(ART)
HMP scheduler
sdcardFS
cpuset group
SKGL & vulkan
f2fs
ART: profile and image
Binder refactor
Cloud profile
odex relayout
EAS scheduler
Generational Concurrent Copying GC
Compilers
&
Tools
Applications
Android Framework
ART(VM)
Native Libraries
HAL / Kernel
Hardware
Mostly Heard
Rarely Seen
行业内其他工作做了哪些事情?
Projects
Custom Rom - Nanoscope
虚拟机-Execution Engine & Compiler
虚拟机-Execution Engine & Compiler
Hot Methods
Startup Methods
Startup Classes
Startup Strings
Profile
Odex file
profile里的methods编译为机器码
Image file
Class pre-init
String pre-resolve
编译时机的控制
profile文件的编辑
image文件的利用
虚拟机-GC
虚拟机-GC
512MB
512MB
compact
copying
Java Heap
Kernel-任务调度
Next
Kernel-内存管理
Kernel-文件系统
编译器优化-ART
Optimization passes:
编译器优化-Redex
编译器优化-PGO(Profile Guided Optimization)
Source
code
Instrumented
program
Profile
data
Optimized
program
Code
Optimization
Layout
ART speed profile
Profile内method编译成机器码
Startup method聚集到一起
Redex Interdex
采集启动过程中加载的class
将dex内容重排使启动class聚集
基于硬件的优化
基于硬件的优化-GPU
CPU
C / Neon
View drawing
View drawing
Hwui
pipeline
CPU fallback
GPU rendering
Render - HWUI
Tools
Demo
定制ROM插桩
时间戳获取:将timer硬件寄存器导出到用户空间
VM和Compiler插桩
Interpreter
JIT
AOT
Tools
Slardar 线上问题聚合
慢函数
卡顿树
Recap
2
从性能角度看,app关心的是如何最大化利用操作系统提供的各种资源
操作系统
EAS(Energy aware scheduler)
?
4+4
4+2+2
?
CFS
Completely fair scheduler
Linux Android
CPU0
CPU1
main
binder
main
binder
main
binder
main
CPU0
main
binder
binder
main
binder
main
binder
main
binder
system
app
操作系统 - 任务调度
Optimizations:
Priority Inherit
Atomic Instructions
Better Locks
ActivityManagerService: boostPriorityForLockedSection
Pthread_mutex: Support priority inheritance mutex
Fuchsia: priority inherit in Fuchsia
操作系统 - 任务调度
EAS(Energy aware scheduler)
?
4+4
4+2+2
?
CFS
Completely fair scheduler
Linux Android
Jato:
调度策略优化
EAS(Energy aware scheduler)
?
4+4
4+2+2
?
CFS
Completely fair scheduler
Linux Android
操作系统 - 任务调度
file
heap
Others
open/mmap
Userspace allocators
dlmalloc, jemalloc...
brk/mmap/madvise..
Ashmem: /dev/ashmem
Graphics:/dev/kgsl, /dev/ion..
Page fault
物理页分配
分配:driver alloc page
回收:driver shrinker callback
Linux Android
操作系统 - 内存管理
File
Java Heap
Native Heap
Anonymous Page
只读/Clean的页
可以直接丢弃回收物理页
匿名页通过swap方式回收
Zram: 在内存中的swap分区,写入压缩,读出解压
madvise
给系统一些提示
操作系统 - 内存管理
ext4 -> f2fs (flash friendly file system)
改善痛点:
操作系统 - 文件系统
General read
Random read
Fragment
Sync
只读文件系统,读取时间解压,CPU解压>IO latency
Squash fs: Android GO
Erofs: Huawei
Fallocate
预先分配占位文件,defrag时将实际文件填入
Atomic write:解决写入顺序问题
mmap代替:keva
操作系统 - 文件系统
2
Reference
Computer architecture
The future of computing: a conversation with John Hennessy
Android Runtime
What’s new in Android Runtime(Google I/O 18)
Deep dive into the ART Runtime(Android Dev Summit 18))
Understanding Android Runtime(ART) for Faster Apps(Google I/O 19)
The Evolution of Android Garbage Collection
Operating system
F2FS: A New File System for Flash Storage
RCU for non-kernel programmers