flutter / flutter/devtools

Performance improvements to CPU profile code

未关闭
#7,917 9 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
dart2wasm devtools app performance P2 product-quality screen: cpu profiler
主要语言
Dart
星标
1.7k
派生
404
平均合并
6 天 17 小时
30 天内合并 PR
18

描述

After having taken a look at the cpu profiling code in DevTools, we found:

* It unnecessarily encodes json maps and decodes them again: [devtools/pull/7916](https://github.com/flutter/devtools/pull/7916)
* It gets `Stream */>` from the websocket and then json decodes strings
=> It would be more efficient to avoid going from utf-8 to string and then to json and instead directly from utf8->json
=> This would probably require some refactoring in various packages, so maybe not easily doable?
* Way too many conversions
* Bytes->String in websocket layer
* String->JSON in `package:vm_service layer`
* JSON -> service objects in `package:vm_service` layer (e.g. `vm_service.CpuSamples`, `vm_service.CpuSample`)
* service objects -> `_CpuProfileTimelineTree` tree structure
=> Uses expandos (!!) to map service objects back to tree nodes
* `_CpuProfileTimelineTree` -> JSON "traceObject" (very expensive operation!)
* Going from JSON "traceObject" back to normal objects in `CpuProfileData.fromJson` which builds json maps with strings and `CpuStackFrame` as values

It seems there's too many conversions from one data structure to another and the representations used for encoding this profiling information doesn't seem very efficient either.

贡献指南

打开贡献指南

调研方向

先阅读 DevTools 中的 CPU 分析流程,包括 package:vm_service、_CpuProfileTimelineTree 和 CpuProfileData.fromJson。查看 devtools/pull/7916,并跟踪列出的每一次转换:从 websocket bytes 经过 service objects 到 traceObject 输出。Done 要求就减少不必要的转换达成共识并进行测量,同时定义重构范围。

由索引模型根据 Issue 内容生成。

评估

技术栈
dart
领域
devtools, performance
Issue 类型
重构
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。