返回 DeepSeek-Reasonix
EXTENSION_RUNTIME_V2_PERF.zh-CN.md
根目录 / docs / EXTENSION_RUNTIME_V2_PERF.zh-CN.md
1 # 扩展运行时 v2 — 性能基线
2
3 软 CI 阈值见 `internal/extension/bench_threshold_test.go`。
4 Benchmark 见 `internal/extension/benchmark_test.go`。
5
6 ## 目标(开发机 / CI 软失败)
7
8 | 操作 | N | 软上限 |
9 | --- | --- | --- |
10 | `BuildDependencyGraph` | 32 组件 | < 50ms |
11 | `DiffRuntimePlan` no-op | 同图 | < 20ms |
12 | `EffectScope.Dispose` | 64 effects | < 50ms |
13
14 ## 增量 vs 全量 rebuild
15
16 - **no-op / interceptor / UI / provider / MCP-only**(`RebuildFrom` + 真子图 patch):**不得**调用 `BuildRuntime`。指标:`NoOpRebuilds` / `SubgraphRebuilds`。
17 - **全量**(`SubgraphSidecar` / `SubgraphFull`):`FullRebuilds` + 完整 `BuildRuntime`。
18
19 测量命令:
20
21 ```bash
22 go test ./internal/extension/ -run 'TestGraphAndPlanLatencyBaseline|TestEffectScopeDisposeBaseline' -count=1
23 go test ./internal/extension/ -bench 'BenchmarkDependencyGraphAndPlan|BenchmarkExtensionKernelStartup' -benchmem -count=3
24 go test ./internal/boot/ -run 'TestIntegrationNoOpDoesNotBuildNewController|TestRebuildFromNoOp' -count=1
25 ```
26
27 ## 缓存命中
28
29 no-op、UI/interceptor-only 以及只滚动 backend 的 Provider/MCP 计划会保持
30 system prompt、tool schemas 与 `CacheHash` 字节稳定。Provider capability 变化通过
31 `providerChanged` 呈现,不会误报 `prefixChanged`;MCP schema 新增、删除或改名则
32 归类为全量 rebuild,并有意重新计算 prefix。保留 `ReuseAssembly` 时仍可跳过
33 skill/command/hook rediscovery。
34
35 ## Sidecar 启动 / drain
36
37 `StartPackagesWithPlan` 收养 Unchanged 客户端;仅启动 Added/Reloaded。
38 Publish 后 `DrainPlan`;默认 drain TTL 30s,超时先 fire cancel 再写
39 `drain-timeout-<gen>` receipt。
40 冷启动 publish 不创建 watcher;存在 drain 时,快速连续 publish 在每个 runtime
41 owner 上共用一个定时 watcher,并只等待最早 drain 的剩余 TTL。每个 owner 的
42 过期 generation 标记最多保留 256 个。
43
44 Receipt 证据仅存在于当前进程,最多保留 32 个 generation、每代 256 条。发生
45 淘汰时按保守策略处理:禁止声称 clean rollback,而不是隐藏证据缺失。
46 消息去重键会随对应 receipt 淘汰而释放。文件 prior 每次写入最多保留 8 MiB,
47 每个 runtime owner 合计最多 32 MiB;超限 prior 不保留,并阻止 clean rollback 判断。
48 已完成的 Provider stream 会立即移除 drain 回调,长寿命 generation 只保留活跃 stream
49 的取消状态。
50
50 lines MARKDOWN