Skip to content
目录

性能优化 ​

MobX 默认已较省;优化重点是缩小依赖面与事务批量,而非再包一层 memo。


1. 依赖面 ​

策略说明
细粒度 observer子组件各自读字段
computed 过滤列表避免 render 里 filter 大数组
observable.ref / shallow大对象、替换式更新
避免 autorun 依赖根 store拆 reaction

2. 更新批量 ​

  • 多字段修改包 action / runInAction。
  • 与 React 事件同批时仍受益。

3. 结构 ​

  • 领域拆多个 store 类,勿一个 observable 巨对象。
  • 远程数据:请求结果一次 runInAction 写入。

4. 监控 ​

Performance profiler + MobX spy(开发);关注 autorun 次数。


5. 总结 ​

MobX 慢几乎都是 observer 依赖过多 或 在热路径创建 computed;先画依赖再改代码。

MIT License.