Skip to content

perf: batch git exec calls for notes, rev-parse, status, and checkpoints#595

Open
svarlamov wants to merge 3 commits intomainfrom
devin/1772084830-perf-batch-git-calls
Open

perf: batch git exec calls for notes, rev-parse, status, and checkpoints#595
svarlamov wants to merge 3 commits intomainfrom
devin/1772084830-perf-batch-git-calls

Conversation

@svarlamov
Copy link
Member

@svarlamov svarlamov commented Feb 26, 2026

Summary

This PR implements performance optimizations to reduce git subprocess overhead by batching git exec calls. The primary bottleneck in git-ai is the number of individual git invocations, especially for operations like git notes show and git rev-parse that are called repeatedly in loops.

Changes:

  • Fix Fix init command #1 & Initial test suit #2: Batch-fetch authorship notes in blame.rs and refs.rs using 2 git calls (1 cat-file --batch-check + 1 cat-file --batch) instead of N individual git notes show calls
  • Fix PR Comment Demos #4: Combine resolve_commit + resolve_parent into single git rev-parse call in diff.rs
  • Fix Cursor extension #5: Skip redundant get_staged_filenames() call in status() when no pathspecs provided (porcelain v2 output already contains staging info)
  • Fix make git-ai init idempotent #7: Read checkpoints once instead of twice in get_all_tracked_files()
  • Add batch_get_authorship_logs() helper function for reuse across codebase
  • Make batch_read_blobs_with_oids() public for cross-module access

Expected impact: Significant reduction in subprocess overhead for blame operations (N commits → 2 git calls), diff operations (2 calls → 1), and status operations (2 calls → 1 when no pathspecs).

Updates since last revision

  • Resolved merge conflict with main in src/commands/diff.rs: the resolve_two_revs function now uses exec_git_with_profile(&args, InternalGitProfile::General)? (combining the PR's ? error propagation + stdout parsing with main's migration from exec_git to exec_git_with_profile). This matches the pattern already used by resolve_commit in the same file.

Review & Testing Checklist for Human

⚠️ Risk level: YELLOW - Core git operations modified without end-to-end testing

  • Test blame command with commits that have authorship notes, especially files with many unique commits. Verify AI/human attribution is correct and performance improves.
  • Test diff command on edge cases: initial commits (no parent), symbolic refs (HEAD, branch names), commit ranges. Verify correct fallback to empty tree hash. Pay attention to the merge-conflict resolution in resolve_two_revs — confirm error propagation via ? behaves correctly when revisions can't be resolved.
  • Test status command with staged files, both with and without pathspecs. Verify staged files are correctly identified without the explicit get_staged_filenames() pre-call.
  • Verify schema version handling: batch_get_authorship_logs() correctly filters by AUTHORSHIP_LOG_VERSION, but the inline batch code in get_commits_with_notes_from_list() does not — it deserializes without a version check. Confirm this difference is intentional.

Notes

  • Only cargo build and cargo clippy were run — no functional tests executed
  • The status.rs change assumes porcelain v2 output correctly identifies staged files; this should be verified with real repos
  • The diff.rs resolve_two_revs now propagates errors with ? instead of the old match on Ok/Err; initial commits fall back to the empty tree hash via the caller's match on resolve_two_revs
  • In get_diff_json_filtered, the parent is resolved via resolve_two_revs(repo, &parent_rev, &to_commit) which redundantly re-resolves to_commit — minor inefficiency but not a bug

Link to Devin run: https://app.devin.ai/sessions/972f0c2bf6d94b17b663d3e7d52da147
Requested by: @svarlamov


Open with Devin

- Fix #1: get_commits_with_notes_from_list uses batch cat-file instead of N individual git notes show calls
- Fix #2: populate_ai_human_authors and overlay_ai_authorship in blame batch-fetch all authorship notes upfront
- Fix #4: resolve_commit + resolve_parent combined into single git rev-parse call
- Fix #5: status() skips separate get_staged_filenames() call when no pathspecs provided
- Fix #7: read_all_checkpoints() called once instead of twice in get_all_tracked_files
- Add batch_get_authorship_logs() helper to refs.rs for reuse across codebase
- Make batch_read_blobs_with_oids() public for cross-module access

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@git-ai-cloud-dev
Copy link

git-ai-cloud-dev bot commented Feb 26, 2026

Stats powered by Git AI

🧠 you    ████████████████████  98%
🤖 ai     ░░░░░░░░░░░░░░░░░░░█  2%
More stats
  • 1.4 lines generated for every 1 accepted
  • 19 seconds waiting for AI
  • Top model: claude::claude-sonnet-4-6 (62 accepted lines, 26 generated lines)

AI code tracked with git-ai

@git-ai-cloud
Copy link

git-ai-cloud bot commented Feb 26, 2026

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 5 additional findings.

Open in Devin Review

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
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.

make git-ai init idempotent

2 participants