Based on the profiling results, here's where the time is being spent:
| Operation | Time (avg) | Breakdown |
|---|---|---|
| Direct shell hook | 0.082s | ⚡ Fastest - pure tool execution |
| ShellCheck alone | 0.029s | Core linting tool |
| shfmt alone | 0.013s | Core formatting tool |
| Pre-commit overhead | ~0.214s | Environment setup cost |
| Local pre-commit run | 0.506s | Tool execution + overhead |
| Global lint function | 0.546s | Tool execution + overhead + config |
| Commit hook context | 0.679s | Full commit simulation |
- Environment initialization: ~0.214s
- Config parsing and validation: minimal difference between local/global
- Hook orchestration: ~0.3s additional overhead
- ShellCheck + shfmt combined: ~0.042s
- Direct shell hook execution: 0.082s (includes file I/O, patching)
- Commit context adds ~0.17s vs direct pre-commit run
- Global config vs local config: ~0.04s difference (minimal)
The slowdown during commits vs "lint" command is NOT due to the tools themselves but due to:
-
Environment Setup (214ms baseline)
- Python environment initialization
- Virtual environment activation for hooks
- Hook repository validation
-
Hook Orchestration (300ms+ overhead)
- File staging/unstaging simulation
- Hook dependency resolution
- Output formatting and collection
-
Commit Context Processing (170ms additional)
- Git integration overhead
- Temporary file management
- Hook stage validation
Direct tools (shellcheck + shfmt): 0.042s ████
Shell hook script: 0.082s ████████
Local pre-commit: 0.506s ██████████████████████████████████████████████████
Global lint function: 0.546s ██████████████████████████████████████████████████████
Commit simulation: 0.679s ███████████████████████████████████████████████████████████████████
- Use direct shell hook:
~/.config/git/hooks/lint-shell.sh file.sh(0.082s) - Use individual tools:
shellcheck file.sh && shfmt -w file.sh(0.042s)
- Accept the overhead: Pre-commit framework provides consistency and reliability
- Optimize hook configuration: Remove unnecessary hooks from commit-time execution
- Consider hook staging: Run lightweight checks on commit, full analysis in CI
- The global vs local config difference is minimal (40ms)
- Environment setup is the primary bottleneck, not tool execution
- Tools themselves are extremely fast (< 100ms total)
The "slowness" during commits is primarily due to pre-commit framework initialization (214ms) plus hook orchestration overhead (~300ms), totaling ~500ms base cost. The actual linting tools (shellcheck + shfmt) run in just 42ms.
This is a normal trade-off: convenience and consistency of the pre-commit framework vs raw execution speed.