compose-performance

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Compose 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

排查步骤

  1. Reproduce one concrete transition and capture the observable evidence: recomposition counts, compiler reports, profiler data, or a clear trace.
  2. Classify the primary axis: parameter stability and skipping, State read phase, or snapshot state written back into an earlier phase.
  3. Check for a false lead: a real data change, a correctness defect, or an unchanged lazy item that is expected to recompose.
  4. Read the corresponding focused reference before proposing a change.
  5. Change one axis at a time and re-measure the same transition.
  6. Finish when the evidence improves at the observed boundary without hiding state changes, caching stale values, or moving work to a less correct owner.
  1. 复现一个具体的过渡效果并捕获可观测证据:重组次数、编译器报告、分析器数据或清晰的追踪信息。
  2. 对主要维度进行分类:参数稳定性与可跳过性、State读取阶段,或快照状态回写到更早阶段。
  3. 排查误导性线索:真实的数据变更、正确性缺陷,或预期会重组的未变更懒加载项。
  4. 在提出修改前,阅读对应的针对性参考文档。
  5. 每次仅修改一个维度,并重新测量同一过渡效果。
  6. 当观测边界处的证据得到改善,且未隐藏状态变更、缓存过期值或将工作转移到正确性更低的所有者时,结束排查。

Topic router

主题指引

SignalRead
Cause is unknown, or several axes may interactDiagnosis
classes.txt
,
composables.txt
, strong skipping, unstable parameters, or collection stability
Stability
Scroll, animation, gesture, layout, or draw State read at frame rate; measured state fed back into compositionDeferred reads
A composable only reads composition locals or accessor-style valuesComposition contracts
State ownership or effect lifecycle is the root causeCompose state and effects
信号阅读文档
原因未知,或多个维度可能相互作用诊断
classes.txt
composables.txt
、强可跳过性、不稳定参数或集合稳定性
稳定性
滚动、动画、手势、布局或绘制阶段以帧率读取State;测量的状态反馈到组合中延迟读取
可组合项仅读取组合本地变量或访问器式值组合契约
状态所有权或副作用生命周期是根本原因Compose状态与副作用

RED/GREEN agent scenarios

RED/GREEN代理场景

  1. RED blames unstable parameters for unchanged lazy rows that recompose during a focus transition. GREEN checks composition and layout back-writing first.
  2. Novel case: an animation value controls only drawing. GREEN reads the State in a draw or layout lambda instead of propagating it through composition.
  3. Counterexample: a screen visibly recomposes because its displayed model actually changed. GREEN does not add stability wrappers or caches merely to lower a count.
  1. RED将焦点过渡期间未变更懒加载行发生重组的问题归咎于不稳定参数。GREEN首先检查组合和布局的回写情况。
  2. 新案例:动画值仅控制绘制。GREEN在绘制或布局lambda中读取State,而非通过组合传递它。
  3. 反例:屏幕明显发生重组,因为其显示的模型确实发生了变化。GREEN不会仅仅为了降低重组次数而添加稳定性包装器或缓存。