Skip to content

perf(git): 使用游标流式分页加载提交历史 - #406

Open
xiaoyumuxi wants to merge 5 commits into
previewfrom
codex/git-history-pagination
Open

perf(git): 使用游标流式分页加载提交历史#406
xiaoyumuxi wants to merge 5 commits into
previewfrom
codex/git-history-pagination

Conversation

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator

概述

修复 #366 中大型仓库打开 Git Log 时一次性读取和重复遍历提交历史的问题。

本 PR 将 macOS 和 Windows 的 Git 历史加载改为共享 Rust Core 提供的游标分页:

  • 引用信息与首屏提交并发加载
  • 后续页面复用同一个有界 git log 流,不再通过深 offset 重走前面的提交
  • 切换仓库、分支、刷新或关闭视图时显式释放游标
  • 保留显式 offset 请求的兼容路径,新客户端统一使用 nextCursor

实现

  • Rust Core 新增 git.references、游标版 git.historyPagegit.historyCursorClose
  • 每个 cursor 使用单槽有界通道、最多一条 lookahead、120 秒空闲回收,并限制最多 8 个活跃会话
  • 保留 5,000 commit 上限和旧 offset 协议兼容
  • macOS 首屏并发加载 references/page,并处理取消、过期结果及 cursor 回收
  • Windows 同步接入 cursor contract、Tauri command translation 和 stale/cancel 生命周期
  • 更新共享 contracts、fixtures 和跨平台测试

这里不依据 .git 目录大小切换策略,因为其体积可能主要来自 blob、pack、LFS 或 reflog,与提交图遍历成本并不稳定相关。新客户端始终使用 cursor。

#390 的关系

#390 主要缩小 Git Log 的 SwiftUI 重绘范围;本 PR 处理数据层的提交历史查询与深分页。两者作用于不同瓶颈,可以叠加。

测试

  • cargo check --manifest-path rust/lithe-core/Cargo.toml
  • ./scripts/verify-rust-core.sh:324 个 unit tests 和 5 个 integration tests 通过
  • ./scripts/test-macos.sh --filter GitModuleTests:33 个测试通过
  • rebase 到最新 preview 后,定向测试 GitModuleTests.gitHistoryAppendsTheNextPageWithoutReplacingEarlierCommits 通过
  • Windows Tauri platform tests:21 个测试通过
  • Windows TypeScript tsc --noEmit 通过
  • shared contracts、service boundaries 和 Windows boundaries 检查通过

Closes #366

@xiaoyumuxi
xiaoyumuxi requested a review from 1lck as a code owner September 2, 2026 06:37
Comment thread windows/tauri/src/features/git/api/git-commits-api.ts
Comment thread windows/tauri/src/platform/core-result-adapter.ts
Comment thread rust/lithe-core/src/git/history.rs
Comment thread rust/lithe-core/src/git/history.rs
@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

@xiaoyumuxi 这次 Review 发现 1 个会阻塞合并的问题:Windows 的 cursor page 仍经过会自动重试的通用读协调器,仓库状态在分页期间失效时会二次消费旧 cursor,导致加载失败并遗留新 cursor。另有 3 个需要一并处理的 P2:独立 refs 适配丢失 ahead/behind,以及 Rust 会话上限在并发首屏请求下可被突破、120 秒 TTL 目前只会在下一次 history 调用时惰性触发。因此当前存在阻塞合并的问题,建议修复后再合并。

整体方向是对的,尤其值得保留单槽有界通道带来的背压,以及 macOS/Windows 对 stale result 返回 cursor 的主动关闭;这两点让分页生命周期比简单 offset 重放清晰很多。

本地验证中,Rust Core comment gate、定向 cursor 分页测试、Windows boundary gate 和测试稳定性静态检查均通过;新增 Swift 分页测试通过并记录为 0.004 秒。当前 Windows 实机测试和 PR 主体 CI 仍在等待,且现有测试尚未覆盖 generation 失效时的 cursor 行为、并发 session cap、真实 TTL 回收和非零 ahead/behind 适配。

@xiaoyumuxi

Copy link
Copy Markdown
Collaborator Author

@xiaoyumuxi Review 中的 4 个问题已在 04ac36b3 修复并推送:

  • cursor page 禁用 generation 自动重试,新增非幂等读取失效测试;
  • Windows refs 恢复 ahead/behind 映射与非零计数测试;
  • Rust session lease 将启动中、读取中和已存储会话统一纳入 8 个上限;
  • 独立 reaper 主动执行 120 秒 TTL 回收,并用注入时间做确定性覆盖。

四个行级线程均已逐条回复并标记 resolved。本地已通过 Rust Core 全量验证(355 个单测、8+5 个集成测试及 Swift bridge)、Core/shared/service/Windows boundary gates、Rust 注释门禁和测试稳定性检查;Swift 分页时序测试为 0.004 秒。当前 PR 的 Windows、Rust/Swift、Swift 和 release CI 仍在排队,合并前请以这些远端结果为准。

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