Skip to content

sidebar: 会话列表加载性能优化#4858

Merged
SivanCola merged 4 commits into
esengine:main-v2from
ttmouse:pr/session-cache
Jun 19, 2026
Merged

sidebar: 会话列表加载性能优化#4858
SivanCola merged 4 commits into
esengine:main-v2from
ttmouse:pr/session-cache

Conversation

@ttmouse

@ttmouse ttmouse commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

问题

ListProjectTree 每次被调用(启动、侧边栏渲染、会话变更)时,都会对 32 个工作区目录逐一调用 ListSessions。每个目录的 ListSessions 需要遍历所有 .jsonl 文件,读取 .jsonl.meta 元数据并解码 JSONL 文件获取预览文本。实测 1121 个会话,每次耗时 1.6 秒。

多工作区用户(10+ 个项目,每个几十个对话)在启动时感知尤为明显。

改动

1 个文件,310 行增量,在 desktop/tabs.goListProjectTree 中增加了三层缓存:

并发读取

32 个会话目录改为 goroutine 并发读取(sync.WaitGroup),共享 map 合并用 mergeMu 保护。首次冷启动从 1.6s 降至 0.87s。

内存缓存(sessionListCache

同一次应用会话内,第二次及后续调用 ListProjectTree 直接从内存返回缓存结果,不触发任何文件 I/O。emitProjectTreeChanged 时自动失效。

磁盘缓存(sessionDiskCache

首次读取后将结果持久化到 ~/.reasonix/project-session-cache.json。下次启动时通过目录签名(文件名 + mtime + 大小)校验缓存有效性——签名匹配则直接从缓存文件恢复(8ms),跳过所有文件读取。签名不匹配时回退到完整读取并更新缓存。

效果(实测 1121 个会话,32 个目录)

场景 优化前 优化后
首次冷启动 1.6s 0.87s
二次启动(磁盘缓存命中) 1.6s 8ms
同次会话重渲染(内存缓存命中) 1.6s 8ms
会话变更后 1.6s 0.87s(重建缓存)

兼容性

  • 纯增量,不改动上游任何接口签名或行为
  • emitProjectTreeChanged 新增两条 invalidate 调用,不影响原有事件流
  • 磁盘缓存放在 ~/.reasonix/ 下,文件缺失时自动降级回完整读取

共同贡献者

  • @SivanCola(修复缓存有效性、补充回归测试并处理 review feedback)

- 并发读取所有工作区的会话目录(goroutine + WaitGroup)
- 内存缓存 sessionListCache:同次会话内重渲染零 I/O
- 磁盘缓存 sessionDiskCache:签名校验后跳过 LoadBranchMeta + previewSession
- 会话变更时(emitProjectTreeChanged)自动失效缓存

效果:10+ 工作区 1100+ 会话,首次 0.87s vs 1.6s,二次启动 8ms
@github-actions github-actions Bot added v2 Go rewrite (1.x) — main-v2 branch, active development desktop Wails desktop app (desktop/**) labels Jun 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d29e591100

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread desktop/tabs.go Outdated
Comment thread desktop/tabs.go
Comment thread desktop/tabs.go
Comment thread desktop/tabs.go
@SivanCola SivanCola merged commit 2c415de into esengine:main-v2 Jun 19, 2026
16 checks passed
@SivanCola

Copy link
Copy Markdown
Collaborator

Follow-up integration #4942 has now been merged.

This PR was already merged into main-v2 and served as the baseline sidebar session-list performance work that #4942 builds on. There is no separate child PR to close here because this PR is already merged, but @ttmouse is credited in #4942's contribution table for the baseline cache/fan-out direction.

Thank you for the original performance work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

desktop Wails desktop app (desktop/**) v2 Go rewrite (1.x) — main-v2 branch, active development

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants