Skip to content

性能:页面只读快照,远端读取全部放到后台 - #59

Merged
NginxL merged 2 commits into
mainfrom
feat/perf-snapshots
Dec 3, 2026
Merged

NginxL merged 2 commits into
mainfrom
feat/perf-snapshots

Conversation

@NginxL

@NginxL NginxL commented Dec 3, 2026

Copy link
Copy Markdown
Owner

做了什么

页面和卡片渲染一律只读内存快照,任何网络、lark-cli、hub 读都放到后台。

  • 快照优先(core ui.Fresh):只要有值就立刻给,后台再刷新;只有什么都没有时才有界等待。值老了,页面上写「n 分钟前的数据,正在更新」,5 秒后自动拉新。日程、中转站、Agent 进度、Persona 四块、今天页里的微信汇总都接上了。
  • 快照落盘:存进库里的 snapshots 表(单条上限 1 MB),重启后第一次打开也立刻出上次的内容;换账号时作废。
  • Persona 四块分开记:等你的 Agent、在跑的 Agent、收件箱、待办,哪块读失败就沿用它上次的值,并标「沿用 n 分钟前的数据」,不再因为一块失败整页每次重读。
  • 存储:SQLite 改成 WAL + synchronous=NORMAL,读走单独的只读连接,后台大批写入时渲染不再排队;数据库文件(含 -wal、-shm)仍是 0600。
  • 「需要我」:一次查询批量取各会话的行(去掉 N+1),今天页、今天卡片、飞书页按存储的变更计数共用一份结果;所有写入默认都会让它作废,只有快照、配额这类记账写入不计。
  • 飞书群列表:渲染读后台发布好的列表,不再拿飞书适配器的锁(2026-12-01 那次 12.6 秒的渲染和网络不通时的群列表读取同时发生)。
  • 诊断:一个常驻线程看着进行中的渲染,超过 2 秒就把各线程的调用栈写进日志一次(每小时最多 3 次,只写文件、行号、函数名);每小时一行各页面的次数、p50、p95、最大值。

性能

本地合成压测(120 个会话、7,800 条消息、远端每次调用延迟 150 ms):

场景 改前 改后
今天页暖读 p95 115.80 ms 3.61 ms
今天页数据过期时 p95 331.13 ms 7.48 ms
今天卡片数据过期时 p95 110.51 ms 1.42 ms
飞书页暖读 p95 103.19 ms 3.10 ms
650 ms 写事务期间的飞书页 759.71 ms 8.60 ms
重启后今天页第一次 329.18 ms 3.66 ms

线上经 hub 的对比(含 VPS↔Mac 往返约 280 ms)见上线后的评论。

怎么验证的

  • bash scripts/test.sh 和 PYTHON=/usr/bin/python3 bash scripts/test.sh 全部通过;新增的回归测试在改动前的代码上都会失败。

注意

  • 数据库改成 WAL 后,旧版本照样能打开(WAL 是数据库文件自己的设置)。

🤖 Generated with Claude Code

NginxL and others added 2 commits December 4, 2026 03:59
…ground

- ui.Fresh answers any kept value at once and reads again behind it (only a first read waits, bounded); old values
  say their age and pull again in 5 s; snapshots persist in the store (1 MB each) and are dropped with the account.
- PersonaToday keeps each of its four parts' last good read; a failed part is reused and marked, not re-read per draw.
- Store: WAL + synchronous=NORMAL, reads on a separate read-only connection; Store.changes counts every write
  (bookkeeping writes opt out), and needs()/counts()/active_groups() are batched and shared per change count.
- Feishu: group candidates come from the list the background read publishes, without the adapter's locks.
- One watchdog thread per UI logs the threads' stacks when a draw passes 2 s (3 an hour); hourly per-page render
  stats (count, p50, p95, max).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 核心:页面先给已有的数据、后台再刷新(老了标「n 分钟前」并 5 秒后拉新),快照存进库里,重启后第一次打开也立刻出;Persona 四块各自沿用上次成功的值。
- 核心:数据库改 WAL,读写分开连接;「需要我」批量查询、按变更计数共用结果。
- 飞书:群列表渲染不再拿适配器的锁;慢渲染(超过 2 秒)记一次线程栈,每小时一行各页面耗时汇总。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NginxL
NginxL merged commit 0a34ce8 into main Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant