示例工程 25-vue-reactivity-streaming

25-vue-reactivity-streaming/demo-01-shallow-bench/README.md

markdown · 0.8 KB

# demo-01-shallow-bench

同一批 7,200 条事件:深响应式 `reactive([])` vs `shallowRef`。
两边都读完求和,强制触发代理;输出耗时与 `isReactive` 结果。

## 运行

```bash
pnpm --filter @tutorial/25-vue-reactivity-streaming-demo-01-shallow-bench start
```

## 验证

```bash
pnpm --filter @tutorial/25-vue-reactivity-streaming-demo-01-shallow-bench smoke
# {"evt":"smoke","ok":true,"deepMs":...,"shallowMs":...,"deepProxy":true,"shallowProxy":false}
```

## 说明

- `reactive` 读数组元素时逐个创建 Proxy;`shallowRef` 数组本身不代理。
- 差距随事件数与读取次数增长,绝对毫秒依机器而变。
- 事件只读时,深层代理没有收益,只有成本。

## 已知限制

- 微基准只测代理与数组操作,不含 DOM 渲染。