Repository navigation
Conversation
Refs #266. Keep legacy byte proofs and no-replace publication; allow only versioned device-local derived cache additions with unchanged base content.
codeasier
left a comment
There was a problem hiding this comment.
性能评估(head 4b93721,对比 main f940ff7)
结论:方向正确。复杂度是线性的,没有 O(n²),峰值内存也没变化。不过有一个持续性成本,建议合并前处理掉。
实测(单机,页缓存是热的,每项跑 3 次)
输入用 wheel_scale_acceptance.write_scale_source 生成:2,000,002 个事件,--events-per-slice 500000,切成 4 个满分片(每个约 137 MB)加 1 个小分片。
| 场景 | main | PR |
|---|---|---|
| 导出耗时 / 峰值 RSS | 50.6–56.0 s / 1302 MB | 61.3–65.2 s / 1302 MB(约 +16%) |
| 复用,字节没变 | 约 4.5 s | 约 5.1–5.6 s(多读一遍文件做 hash) |
复用,加了 memory_allocation_cache_v1_<dev>(每片约 150 万行) |
约 4.8 s,报 member hash changed(预期行为) | 15.2–16.4 s,复用成功 |
overview / metadata,漂移后 |
— | 约 21 s(未漂移时约 10–11 s) |
| SQLite 临时文件峰值 | 4.3 MB | 74.9 MB(≈ 单表编码后的大小,不随分片数增加) |
单分片拆解(50 万行):
hash_file0.18 s;member_content2.72 s,其中trace_entry_0这张表占 1.86 s。- 带 UDF 但不排序时是 1.64 s,纯
SELECT *是 0.44 s。 - 所以瓶颈是逐行调用 Python UDF
pt_snap_row,约 3.3 µs/行;ORDER BY只占约 10%。
主要风险
- proof 不会刷新。 Insight 写入缓存表后,文件字节永久漂移,manifest 里的 hash 也不更新。所以之后每次 import 复用、
overview、metadata(ImportMetadataService.inspect→inspect_owned_cache)都会重新做一遍全量内容比对。按线性外推(推断),1 亿事件、200 个分片时,每次调用要多出约 9 分钟;callstack 更深时还会更多。 - 导出时一定会算 proof,每个成员至少多一次全表扫描。另外,
build_compatible_manifest前后已经各做了一次 hash,finalize 阶段的inspect_owned_cache又会再做两次。
建议
- 内容比对通过后,把新的字节 hash 记下来(比如写到 sidecar 里,不改 manifest),这样下次直接走快路径。如果不打算这么做,至少在文档里写明这个持续成本。
- 有 INTEGER PK 或稳定 rowid 的大表,改成按
ORDER BY rowid流式读取,在 Python 里分批编码后做 sha256,不再每行调一次 UDF。单表实测快约 2.3 倍(0.82 s 对 1.86 s),也不需要临时 B-tree。没有稳定 rowid 的小表可以继续用现在的排序方案。另外试过"每行 sha256 后做多重集加法聚合、不排序",实测 2.12 s,反而更慢,不推荐。 - 导出时已经算出的 hash 直接传给 finalize 复用。快路径上的后置复核可以改成比对 stat(size/mtime/inode),不必再读一遍整个文件。
- 可选:各成员的 proof 互相独立,可以按进程并行计算。
以上数字都是实测;hash 次数是读代码统计的,大规模估算和 rowid 方案的整体收益属于推断(rowid 方案只测了单张表)。本评审只是记录,不构成 approve。
Avoid duplicate P0 validation within metadata/overview and retain a bounded in-process ownership proof cache guarded by complete content hashes. Keep cold-process proof costs and all mutation/transport checks explicit. Refs #266
|
已在 a237940 处理这条性能评审中的重复验证,并补充冷进程成本说明。 确认调用链:普通查询的 DatasetResolver 不要求 ownership proof,但 overview → ImportMetadataService.inspect → inspect_owned_cache,以及 metadata,确实会触发。现在 metadata 复用同次操作已经完成的 P0 校验,overview 传递同一个 resolved dataset,避免二次基础验证。该结果必须同时匹配根路径、完整内容 fingerprint、manifest 和文件 generation;P0 结果本身不能充当 ownership 证据。 另加最多 16 个根目录的进程内 LRU,仅缓存已经完成全部 ownership 校验的结果。key 覆盖完整 manifest 字节及所有成员文件字节,因此包含 proof 版本/schema、identity、metadata 等上下文。命中前后仍读取完整 hash,检查 inventory、sidecar、路径和硬链接;结果深拷贝、并发锁保护,失败驱逐。没有写入 artifact/sidecar,也没有用 stat 替代内容验证。默认和 immutable 模式下,同大小且恢复 mtime 的基础数据篡改都会拒绝。 小型隔离复核(合成 100,000 事件、4 个分片,每片新增 25,000 行派生缓存,各 3 次;对比本 PR 上一 head 4b93721,不是 main 或本评审的 200 万事件测试):
持续成本的边界现已写入中英文文档:新的 CLI 进程在成员字节漂移后仍需扫描基础内容;首次导出生成 proof 的成本也仍然存在。本次没有引入跨进程持久化信任协议,也未改变 v1 的类型保真、多重集排序合同。按 rowid 改序会改变现有 proof 定义,不能直接作为等价优化替换。 新增 26 项缓存/复用回归;本地相关测试 699 passed / 2 skipped,Ruff、Black、类型检查(0 errors)及 wheel 构建/源码字节审计通过。独立安全 review 已检查缓存 key、跨目录隔离、并发、异常驱逐和 mutation guards。新 head 的远端 CI 正在运行,将按该 commit 核验终态。 |
|
最终核验:当前 head a237940 的两组 CI 均已成功终止,无手动重跑。
已读回分支与源码 tree bc8d7b1aff531ad4497aea6b58a694420c570f68,匹配本地验证内容;author/committer 均为本次批准的 codeasier noreply 身份。此条与上一条性能回复更新 PR 初始描述中的旧 head 验证记录。PR 保持 draft/open,#266 保持 open,等待审阅。 |
|
关闭说明:#266 改为采用 #268 的 本 PR 的严格规则(只允许新增
当前的要求是:数据异常(如删表、损坏)时必须明确报错,或者触发重建。具体意见见 #268 的评审。分支保留,其中的竞态测试思路后续可以参考。 |
Summary
Refs #266. This is a focused runtime fix with synthetic regressions, not a repeat of the completed full E2E acceptance or a release change. Keep the issue open for review.
ptSnap.memberContentevidence for every original SQLite schema object and every original table, including metadata, dictionary and lifecycle references. Type-tagged, length-framed row encoding preserves NULL/integer/real/text/blob distinctions and duplicate multiplicity; SQLite sorts and Python streams the rows.memory_allocation_cache_v1_<this member deviceId>table. Validate schema before hashing base rows; do not scan permitted derived cache content. Reject other table names/versions/devices, new indexes/views/triggers, and base schema/data changes.Validation
Frozen source tree:
1a2e414e91d73be9e9a0048bdf5af9009332a21b.git diff --checkpassed.ad6fdd9a0732a8c6c5eb2886e95c3d4c5be1ca046f09518598023f2898f94a21. This is a development verification artifact, not a release.Remote CI is pending and will be checked for this exact head. No full E2E, live snapshot/session, paid model, user Mac, #264 modification, release workflow change, merge or issue closure.
Snapshot runtime provenance
Snapshot provenance decision: no-update
Snapshot provenance no-update reason: Changes are limited to core proof/export/metadata logic, synthetic tests and documentation; no files under src/pt_snap_cli/snapshot/ change.