前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Compose 与原生启动性能对比

Compose 与原生启动性能对比

作者头像
codelang
发布2022-11-30 14:45:03
9790
发布2022-11-30 14:45:03
举报
文章被收录于专栏:codelangcodelang

Macrobenchmark 接入

官方接入文档:macrobenchmark[1]

接入运行报错:

代码语言:javascript
复制
java.lang.RuntimeException: Baseline profiles aren't supported on this device version
 	at androidx.benchmark.macro.CompilationMode$Partial.broadcastBaselineProfileInstall(CompilationMode.kt:261)
 	at androidx.benchmark.macro.CompilationMode$Partial.compileImpl$benchmark_macro_release(CompilationMode.kt:285)
 	at androidx.benchmark.macro.CompilationMode.resetAndCompile$benchmark_macro_release(CompilationMode.kt:73)
 	at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmark(Macrobenchmark.kt:139)
 	at androidx.benchmark.macro.MacrobenchmarkKt.macrobenchmarkWithStartupMode(Macrobenchmark.kt:301)
 	at androidx.benchmark.macro.junit4.MacrobenchmarkRule.measureRepeated(MacrobenchmarkRule.kt:102)
 	at androidx.benchmark.macro.junit4.MacrobenchmarkRule.measureRepeated$default(MacrobenchmarkRule.kt:92)
 	at com.codelang.benchmark.ExampleStartupBenchmark.startup(ExampleStartupBenchmark.kt:30)

搜了下 stackoverflow[2] ,不支持 Android 12 的设备,在 issueracker[3] 上 google 也给了回复,不支持在 Android 12L 上运行,建议在小于等于 31 的 API 上运行:

由于我需要测 Compose 项目,所以根据答主所述,需要引入 profileinstall-1.2.0-alpha 版本,来覆盖掉 compose-ui 透传引入的 profileinstall 版本

测试:

此次测试运行的是 release 版本,并且每次测试结束都会让 Android Studio 静置一会,然后杀死 java 进程。

数据并不能保证很准确,仅供参考,因为在不同的电脑和环境下,都会产生不同的数据。

本次测试的启动页面是列表,原生采用 RecyclerView 实现,Compose 采用 LazyColumn 实现。

电脑配置:

  • CPU:1.4 GHz 四核 Intel Core i5
  • 内存:8 GB 2133 MHz LPDDR3

模拟器:

  • Android 11

演示代码地址:

  • https://github.com/MRwangqi/ApkAnalysis[4]

点击绿色运行按钮即可开始测试:

测试结果

每组测试用例自动执行 5 遍,结果会输出这 5 次中的最小值、中值、最大值,我们取中值来对比可能比较合理点:

Compose 与原生启动性能对比.png

从本次测试结果来,Compose 的冷启动略逊于原生,两者相差 124ms,但在热启动与温启动状态下,Compose 性能又优于原生

参考资料

[1]

macrobenchmark: https://developer.android.google.cn/studio/profile/macrobenchmark-overview#bumblebee

[2]

stackoverflow: https://stackoverflow.com/questions/71174855/baseline-profiles-arent-supported-on-this-device-version

[3]

issueracker: https://issuetracker.google.com/issues/228222110?pli=1

[4]

https://github.com/MRwangqi/ApkAnalysis: https://github.com/MRwangqi/ApkAnalysis

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-07-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 扣浪 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Macrobenchmark 接入
  • 测试:
  • 测试结果
  • 参考资料
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档