Repository navigation
性能:「需要我」只重读有新消息的会话 - #60
Merged
Merged
Conversation
- Store keeps a per-chat version (new, edited, recalled, blocked and history messages; chat rows; gone and back) and a generation for writes it cannot place (an account wipe, a migration); writes that touch no message or chat row say so (chat_ids=()). - ChatsToday caches each chat's message-derived part of needs() by (chat, version, limit, generation), at most 600 chats (least recently used out), rereads the changed ones in one batch, and never stores a read a newer commit overtook. Recompute after one chat's write: 106.77 ms -> 1.45 ms median on 387 chats / 160k messages. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- 核心:每个会话记版本号,「需要我」按会话缓存,写入后只重读版本变了的会话(今天卡片在首页每次刷新几乎都要重算,现在从约 50 ms 降到 2 ms 以内);结果和全量重算一致。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
做了什么
「需要我」(今天页、今天卡片、飞书页共用)改成按会话增量重算:
为什么
0.11.76 上线后第一小时的扩展内渲染统计:其他页面 p95 都在 1–5 ms,只有首页的今天卡片 p50 53 ms / p95 79 ms。原因是首页每 2 分钟刷一次卡片,期间总有新消息写入,「需要我」每次都要重读约 8,000 行消息(在线上库的副本上测:每次 40–55 ms,其中 85% 在取行和转字典)。
效果
同样规模的合成数据(387 个会话、16 万条消息),写入一个会话后的重算:中位数 106.77 ms → 1.45 ms,最慢 1.84 ms;随机写入后增量结果和全量重算完全一致。线上对比见上线后的评论。
怎么验证的
bash scripts/test.sh和PYTHON=/usr/bin/python3 bash scripts/test.sh全部通过;新测试在改动前的代码上失败。🤖 Generated with Claude Code