perf: skip managed repo lookup for intermediate post-checkout during rebase#567
perf: skip managed repo lookup for intermediate post-checkout during rebase#567
Conversation
…rebase During --rebase-merges, git fires post-checkout for every intermediate checkout operation. In hooks mode each invocation spawns a new process, reads the state JSON, opens the repository, and runs managed hook logic that is effectively a no-op during rebase (post-rewrite handles attribution at the end). This adds two optimizations: 1. In hook_requires_managed_repo_lookup, skip the expensive repository open for post-checkout events during rebase unless this is a terminal event (abort or pull-rebase fallback). 2. In handle_git_hook_invocation, when we already determined there is no forward target and no repo was opened, return immediately instead of re-reading the state file in execute_forwarded_hook. Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
|
No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits. |
|
|
Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
devin fix the lints |
Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
perf: skip managed repo lookup for intermediate post-checkout during rebase
Summary
Fixes the
rebase_merges / current_hooksmargin check failure from PR #530 (27.255% > 25.0%threshold).During
--rebase-merges, git firespost-checkoutfor every intermediate checkout operation (topology recreation). In hooks mode, each invocation spawns a new process that:should_forward_repo_state_first)find_hook_repository_from_context)Two optimizations:
Skip repo lookup for intermediate
post-checkoutduring rebase —hook_requires_managed_repo_lookupnow returnsfalseforpost-checkoutwhen a rebase is in progress, unless it's a terminal event (rebase --abortorpull --rebasefallback). This matches wrapper-mode behavior where intermediate checkout events don't get individual checkout hook processing.Avoid redundant state file re-read — When
should_forward_repo_state_first(None)already returnedNone(no forward target) and no repo was opened, skip the call toexecute_forwarded_hookwhich would re-read the same state file.Local nasty benchmark result after fix:
6/6 margin checks passing(hooksrebase_mergesdropped from ~27% to ~11% slowdown vs wrapper).Review & Testing Checklist for Human
checkout_hooks::post_checkout_hook()for intermediate rebase checkouts is safe. Therun_managed_hook("post-checkout")handler does real work including callingcheckout_hooks::post_checkout_hook(). By skipping the repo lookup, this entire handler is skipped for non-terminal rebase checkouts. Confirm this is consistent with wrapper-mode behavior (where the wrapper handles rebase as one command, not per-checkout).!is_rebase_abort_reflog_action() && !is_pull_reflog_action(). Are there any other terminal rebase events that arrive viapost-checkoutand need managed processing?cached_forward_dir.is_none() && repo.is_none()) doesn't break edge cases whereGIT_DIRmight not be set in the hook environment (e.g., worktrees, unusual git configurations). The assumption is that the env-based state file lookup is authoritative whenrepoisNone.Notes
cargo testrun are pre-existing onmain(snapshot version mismatches and a network error) — not introduced by this change.