perf(trace): post-commit starts three git processes for each committed file

未關閉
#3,756 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
4/5
預估耗時
3-5 天
新手友好度
62/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
git, go
領域
cli, performance

研究方向

Start with settleCommittedLines in app/cli/pkg/action/trace_hook_handler.go and FileAt in app/cli/internal/trace/git/lines.go; check how both ExecClient and GoGitClient read committed files. Then inspect recordRootChanges in app/cli/pkg/action/trace_agent_hook.go and the relevant existing tests. Done when both callers can read multiple paths without resolving the same commit separately for every file, and paths missing from the commit still produce no content.

由索引模型根據 Issue 內容生成。

描述

chainloop component/CLI performance trace-provider
Problem

The post-commit hook of Chainloop Trace starts 3 git processes for each committed file that has pending AI lines. A large commit makes the hook slow.

settleCommittedLines (app/cli/pkg/action/trace_hook_handler.go) calls client.FileAt(repoRoot, sha, path) one time for each pending path in each session. ExecClient.FileAt (app/cli/internal/trace/git/lines.go) runs these commands for each call:

  1. git rev-parse --verify --quiet <sha>^{commit}
  2. git cat-file -e <sha>:<path>
  3. git cat-file blob <sha>:<path>

The commit SHA is the same for all the files. Thus step 1 runs again for each file without a reason.

Measurement

Local clone of this repository (3.3k files). One commit changes 301 files, and all the changes are AI lines that are pending.

Item Value
Git processes that post-commit starts More than 900
Time of post-commit Approximately 5.2 s

This is on main. It is not caused by #3631.

Suggested fix

Read all the files with one git cat-file --batch process. Send one <sha>:<path> line for each path on stdin. For a path that is not in the commit, Git prints <sha>:<path> missing. Use this result as "no content", as FileAt does now. Resolve the commit one time before the loop.

For example, add a Client method that takes a revision and a list of paths and returns the content by path. The GoGitClient version can read the commit tree one time.

recordRootChanges (app/cli/pkg/action/trace_agent_hook.go) calls FileAt for each changed path in the same way, during PostToolUse for Bash calls. The same method can fix that caller too.

主要語言
Go
星號
582
分支
61
平均合併
12 小時 47 分鐘
30 天內合併 PR
137

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

chainloop-dev/chainloop 的其他 Issue

查看 chainloop-dev/chainloop 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。