Skip to content

fix: optimize prepare-commit-msg hook performance for large repos#553

Merged
gtrrz-victor merged 2 commits intomainfrom
fix/prepare-commit-msg-performance
Mar 2, 2026
Merged

fix: optimize prepare-commit-msg hook performance for large repos#553
gtrrz-victor merged 2 commits intomainfrom
fix/prepare-commit-msg-performance

Conversation

@pfleidi
Copy link
Contributor

@pfleidi pfleidi commented Feb 27, 2026

Summary

  • Replace getStagedFiles with native git CLI: Swap go-git's worktree.Status() (O(all files), scans entire working tree) with git diff --cached --name-only (constant time, uses git's optimized index and fsmonitor)
  • Cache staged files across sessions: Compute staged files once in filterSessionsWithNewContent and pass via contentCheckOpts struct, eliminating up to 3×N redundant calls for N sessions
  • Optimize getLastPrompt: Read prompt.txt directly from the shadow branch tree instead of calling extractSessionData() which parses the full transcript (token counting, context generation, prompt extraction)
  • Add benchmark harness: BenchmarkPrepareCommitMsg with 6 sub-benchmarks (Small/Medium/Large repo × 1/3 sessions) and BenchmarkGetStagedFiles for isolated measurement

Also includes the prior fix for entire explain hanging on repos with many checkpoints (commit eff1e18d).

Test plan

  • mise run fmt — clean
  • mise run lint — 0 issues
  • mise run test:ci — all tests pass (unit + integration)
  • Benchmarks run successfully at all repo sizes
  • Manual test: git commit with Entire enabled on a large repo no longer hangs

🤖 Generated with Claude Code

@pfleidi pfleidi requested a review from a team as a code owner February 27, 2026 23:13
Copilot AI review requested due to automatic review settings February 27, 2026 23:13
@cursor
Copy link

cursor bot commented Feb 27, 2026

PR Summary

Medium Risk
Changes git hook behavior and performance by switching staged-file detection to git diff --cached and refactoring session content checks, which could affect trailer linking decisions in edge cases or environments where git execution differs.

Overview
Performance-focused refactor of git hooks and checkpoint listing. prepare-commit-msg now detects staged files via native git diff --cached --name-only, caches that result across sessions, and threads it through a new contentCheckOpts path to avoid repeated expensive checks.

Avoids heavy transcript parsing in hot paths. getLastPrompt and entire explain’s branch checkpoint list now read prompt.txt directly from git trees (including a single cached metadata-branch tree), instead of loading/parsing full session transcripts per checkpoint.

Reduces expensive go-git diffs in list views. Temporary checkpoint filtering switches from a full diff (hasCodeChanges) to an O(1) tree-hash comparison (hasAnyChanges), and adds benchmark coverage for PrepareCommitMsg and getStagedFiles plus test updates for the new APIs.

Written by Cursor Bugbot for commit ea28a47. Configure here.

@pfleidi pfleidi changed the base branch from main to fix/explain-hang-performance February 27, 2026 23:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Improves performance of Entire’s git hook and checkpoint listing paths in large repositories by avoiding expensive go-git operations and repeated work, while adding benchmarks to measure improvements.

Changes:

  • Replaces staged-file detection with git diff --cached --name-only and caches staged files across session checks.
  • Optimizes last-prompt retrieval by reading prompt.txt directly from git trees instead of parsing full transcripts.
  • Reduces entire explain checkpoint-list overhead by reading prompts from the metadata tree and using a cheap “any changes” check.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
cmd/entire/cli/strategy/manual_commit_hooks.go Caches staged files, switches staged-file detection to git CLI, and optimizes last-prompt lookup via prompt.txt in trees.
cmd/entire/cli/strategy/mid_turn_commit_test.go Updates tests to pass staged files via the new contentCheckOpts path.
cmd/entire/cli/explain.go Avoids slow transcript reads in list views by reading prompts from the metadata tree and using a lightweight tree-hash change check.
cmd/entire/cli/strategy/preparecommitmsg_bench_test.go Adds benchmark harnesses for PrepareCommitMsg and staged-file detection across repo sizes/session counts.

Base automatically changed from fix/explain-hang-performance to main March 1, 2026 23:47
pfleidi and others added 2 commits March 2, 2026 11:05
Replace go-git's worktree.Status() with native `git diff --cached` in
getStagedFiles (constant time vs O(all files)), cache the staged files
list across sessions to eliminate redundant calls, and read prompt.txt
directly from the shadow branch tree instead of parsing the full
transcript in getLastPrompt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Entire-Checkpoint: b4ec64cad4b6
Entire-Checkpoint: 1e3fe3c13bbf
@gtrrz-victor gtrrz-victor force-pushed the fix/prepare-commit-msg-performance branch from 26377af to 35dec30 Compare March 2, 2026 00:09
@gtrrz-victor gtrrz-victor merged commit 6660d99 into main Mar 2, 2026
6 checks passed
@gtrrz-victor gtrrz-victor deleted the fix/prepare-commit-msg-performance branch March 2, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants