Skip to content

perf(guardrails): block-dangerous-git.sh has 127 external-command call sites, the most in the set - reduce process spawns #3529

Description

@kyle-sexton

Summary

Child of #3508. guardrails/hooks/block-dangerous-git.sh has the highest external-command call-site count of any hook in the marketplace (127) and timed out 59 times in the measured window.

This was initially left unfiled on the assumption a parallel session had claimed it. That session has confirmed it has not claimed this file and is not working it — its scope is two files in disk-hygiene. So this is unowned and is the largest single reduction opportunity in guardrails.

Measured

Plugin guardrails
Hook hooks/block-dangerous-git.sh
Event(s) PreToolUse:Bash + PreToolUse:PowerShell
Timeouts in window 59
External-command call sites 127 — highest in the set
Configured timeout 15 s

Durations are deliberately omitted as a ranking signal: spawn cost on the affected host is bimodal with a 15.7x spread (see #3508), so cross-hook duration comparisons are unreliable. The call-site count is the durable number.

Why this one matters most

At a measured 0.3-0.9 s per process spawn, every call site that executes is most of a second. 127 call sites is an upper bound (many sit in branches), but even a modest executed fraction dominates the hook's wall-clock. A completed fix on a comparable launcher went from 4 spawns to 1 and improved median wall-clock 3.71x.

Proposed work

  1. Count spawns first, before changing anything. Use a PATH shim directory of wrapper scripts that log their own name then exec the real tool; diff the count before and after. Deterministic, so it survives the host's drift, and cheap for a reviewer to verify.
  2. Collapse multi-jq call sites into a single jq program per invocation.
  3. Replace grep/sed/cut/tr/basename/dirname on the hot path with bash builtins.
  4. Watch for x="$(f)" — command substitution forks a subshell, which on MSYS is a real process spawn. A builtins-only helper that reports on stdout still costs a full process; hot-path helpers must assign to a global.
  5. Early-exit before any spawn when the invocation is not a git command at all — this guard fires on every Bash and PowerShell call but only acts on dangerous git forms.

Acceptance criteria

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyFully specified and briefed; eligible for autonomous pickup from the frontier.priority: highSignificant impact, or blocks an imminent release; staff this cycle.work-class: scopedA briefed fix or small feature; blast radius bounded by the brief, tests exist.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions