compose-performance
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCompose performance
Compose性能
Core principle
核心原则
Measure one user-visible transition, identify the runtime axis that causes the
work, then apply the smallest correction at the phase or boundary where that
axis begins.
针对一项用户可见的过渡效果进行测量,找出导致工作负载的运行时维度,然后在该维度起始的阶段或边界处应用最小的修正。
Procedure
排查步骤
- Reproduce one concrete transition and capture the observable evidence: recomposition counts, compiler reports, profiler data, or a clear trace.
- Classify the primary axis: parameter stability and skipping, State read phase, or snapshot state written back into an earlier phase.
- Check for a false lead: a real data change, a correctness defect, or an unchanged lazy item that is expected to recompose.
- Read the corresponding focused reference before proposing a change.
- Change one axis at a time and re-measure the same transition.
- Finish when the evidence improves at the observed boundary without hiding state changes, caching stale values, or moving work to a less correct owner.
- 复现一个具体的过渡效果并捕获可观测证据:重组次数、编译器报告、分析器数据或清晰的追踪信息。
- 对主要维度进行分类:参数稳定性与可跳过性、State读取阶段,或快照状态回写到更早阶段。
- 排查误导性线索:真实的数据变更、正确性缺陷,或预期会重组的未变更懒加载项。
- 在提出修改前,阅读对应的针对性参考文档。
- 每次仅修改一个维度,并重新测量同一过渡效果。
- 当观测边界处的证据得到改善,且未隐藏状态变更、缓存过期值或将工作转移到正确性更低的所有者时,结束排查。
Topic router
主题指引
| Signal | Read |
|---|---|
| Cause is unknown, or several axes may interact | Diagnosis |
| Stability |
| Scroll, animation, gesture, layout, or draw State read at frame rate; measured state fed back into composition | Deferred reads |
| A composable only reads composition locals or accessor-style values | Composition contracts |
| State ownership or effect lifecycle is the root cause | Compose state and effects |
| 信号 | 阅读文档 |
|---|---|
| 原因未知,或多个维度可能相互作用 | 诊断 |
| 稳定性 |
| 滚动、动画、手势、布局或绘制阶段以帧率读取State;测量的状态反馈到组合中 | 延迟读取 |
| 可组合项仅读取组合本地变量或访问器式值 | 组合契约 |
| 状态所有权或副作用生命周期是根本原因 | Compose状态与副作用 |
RED/GREEN agent scenarios
RED/GREEN代理场景
- RED blames unstable parameters for unchanged lazy rows that recompose during a focus transition. GREEN checks composition and layout back-writing first.
- Novel case: an animation value controls only drawing. GREEN reads the State in a draw or layout lambda instead of propagating it through composition.
- Counterexample: a screen visibly recomposes because its displayed model actually changed. GREEN does not add stability wrappers or caches merely to lower a count.
- RED将焦点过渡期间未变更懒加载行发生重组的问题归咎于不稳定参数。GREEN首先检查组合和布局的回写情况。
- 新案例:动画值仅控制绘制。GREEN在绘制或布局lambda中读取State,而非通过组合传递它。
- 反例:屏幕明显发生重组,因为其显示的模型确实发生了变化。GREEN不会仅仅为了降低重组次数而添加稳定性包装器或缓存。