性能优化提案:历史加载剔除流式分块事件(附完整实现与测试) #2598
dingdingfox
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
中文
提案:
session.history历史页省略assistant/chunk流式分块增量(附完整实现、测试与 Agent Note,欢迎直接取用)。现象
手机端(经 Tailscale)打开会话历史需要 10 秒以上;桌面端随会话增长也越来越慢。
根因(实测)
session.history按消息数分页(默认 50 条消息),然后发送页内 seq 范围内的全部事件。实测一个普通的重负载会话:50 条消息展开为 26,562 条assistant/chunk事件、约 5.4MB JSON——其中约 99% 是仅用于流式动画的分块增量。assistant/message事件本身携带完整内容(message.content),对话 reducer 渲染历史时直接使用这些事件,分块对历史查看者没有任何价值。方案
packages/host/apiproxy):historyPage(session.history、detached 历史、subagent.history共用)在分页前过滤assistant/chunk。分页边界、hasMore语义不变;单页从 5.4MB 降到约 200KB(约 50 倍)。packages/client/runtime):loadOlder的连续性断言从「精确相邻」放宽为「确实更旧」(被剥离的分块会在页间留下预期 seq 间隙);非更旧的页仍然 fail-soft。验证
pnpm run typecheck✅ / oxlint 0 错误 ✅api-proxy-history-chunks.spec.ts(attached + detached 双路径)+ 更新session.client.spec.ts,53 测试全过 ✅verify-translation-pairing(937 对一致)✅ /verify-agent-note-format✅代码
完整实现(含中英双语 Agent Note)在分支:https://github.com/dingdingfox/deepseek-harness/tree/perf/history-omit-streaming-chunks
如果团队认可这个方向,可以直接取用或开放外部 PR(当前仓库未开放外部 PR,CONTRIBUTING.md 注明现阶段不接受)。
English summary
Proposal:
session.historypages should omitassistant/chunkstreaming deltas — with a complete implementation, tests, and an Agent Note available on the branch above.assistant/chunkevents (~5.4 MB JSON, ~99% streaming-only payload). Phone history loads take 10+ seconds over Tailscale; the desktop degrades too as sessions grow.historyPagefiltersassistant/chunkbefore paginating (same message window, ~50x smaller pages;hasMoreand page boundaries unchanged); the clientloadOldercontinuity assertion relaxes to "actually older". The stored log and live mux stream keep every chunk.Happy to adapt the approach to team preferences.
All reactions