Repository navigation
perf(host-core): 每轮结束和切换模型时不再读取整个对话记录 - #2349
Conversation
session.saveActiveRevision runs after every turn and session.configure on every model, mode or permission switch. Both read and parsed the whole transcript under the host lock, so a 40 MB session paid 80-160 ms per call and every other request queued behind it. A session without revision rows now returns from the index alone; a regenerated one reads an id-closed suffix back to its latest revision root, which yields the same positions and keep-last contents as the full read, and skips restating a root whose stamp is already right. Configure returns the summary without reading messages. Imports drop pager stamps because no revision rows come with them, as forks already do. closes vastsa#2348
|
@zszz3 is attempting to deploy a commit to the vastsa's projects Team on Vercel. A member of the Team first needs to authorize it. |
vastsa
left a comment
There was a problem hiding this comment.
已独立验证,可以合入。
使用本次从主干 30b026e 与候选 f680fee 分别构建的 debug Host,通过真实 stdio RPC 向隔离临时数据目录写入 320 条、约 40MB 的历史消息,同一脚本各测 5 次中位数:普通 saveActiveRevision 138.82ms → 0.06ms,configure 139.44ms → 0.16ms,重新生成后保存 286.91ms → 6.87ms。性能问题在主干真实存在;候选避开无修订会话的全文读取,并保持已盖章分支的增量读取。
真实 RPC 同时验证修订 1 → 2 来回激活,原回答/新回答正确,全部 320 条前缀保留。导入不携带 revision rows,移除孤立 pager 标记与该边界一致。已复核后缀闭包与 keep-last 顺序、异常 identity 的全文回退。最新候选 sessions:: 151/151、suffix_tests 2/2 通过;上一轮独立 200 组重复 ID 对照在相同 Host 源码上通过。本次没有运行完整桌面 UI 或付费模型请求。
当前 base 30b026e 已包含于候选;最新实际 PR merge ref 与候选文件树相同(5acb015168ca213cf6d1b561c360c05899900198),diff check 通过。五项 Actions 全部成功,包括 Windows transcript E2E 与 Electron E2E。Vercel 失败来自贡献者的团队授权要求,与 Host 构建无关。
Closes #2348
问题
每轮对话结束时调用的
session.saveActiveRevision,以及切换模型 / 模式 / 权限时调用的session.configure,都会在 host 全局锁里把整个 transcript 读出来解析一遍。会话越长越慢,期间其它请求也要排队。改动(只改 host-core)
message_revisions,没有记录就直接返回,不读 transcript。所有给用户消息打重新生成标记的路径都会先写这张表。transcripts::read_closed_message_suffix,从文件末尾往前读,读到最近一条带重新生成标记的用户消息为止,并且会继续往前扩,直到这段里的每条消息第一次出现的位置也都包含在内。这样去重后的位置和内容跟读整份文件完全一样。layout 里有解析不了 id 的行,或者末尾有异常行时,照旧读整份文件。revisionCount/activeRevision已经正确时,不再调用update_message重写整份文件。session.configure只读session_summary,不再读消息。session.import导入时去掉重新生成标记(导入不带 revision 记录,fork 本来就会去掉)。不去掉的话,上面的提前返回会让导入会话一直显示几个不存在的版本。效果(release host,毫秒)
session.configure测试
cargo test -p host-core:1277 通过,1 个失败(review_rpc_records_workspace_scratch_and_approved_external_write_edit),本机/tmp环境问题,main 上一样失败。cargo fmt --check通过;clippy 无新增警告。