Repository navigation
Make the pre-commit hooks about twice as fast and fix the sign-off line - #282
Open
joshwong-cs wants to merge 9 commits into
Open
joshwong-cs wants to merge 9 commits into
joshwong-cs wants to merge 9 commits into
Conversation
This comment was marked as outdated.
This comment was marked as outdated.
1 similar comment
This comment was marked as outdated.
This comment was marked as outdated.
validate_scan only adds a commit trailer but cli.py imported the full scanning stack (Presidio, spaCy, aiohttp, proxy.py) at startup. Deferring each hook import to its subcommand cuts validate_scan from 0.95s to 0.43s. Signed-off-by: BIST pre-commit check
proxy.py acceptors only check for shutdown after their 1-second select() call returns, adding ~0.8s to every run_scan. Run a single acceptor and wake it with a dummy connection once trufflehog exits to avoid that wait. Signed-off-by: BIST pre-commit check
The Presidio analyzer loaded on every run, even when no staged file had an extension Presidio scans. Check paths first, and import and load Presidio only when files need scanning, saving roughly 0.4s. Files are scanned in a plain loop, as the per-file tasks never ran concurrently. Signed-off-by: BIST pre-commit check
Loading and running the Presidio analyzer blocked the event loop. That didn't slow the scan because trufflehog already starts first but it held up every other task including the release check once it runs alongside the scans. Each CSV is also read in one go rather than line by line which is slightly faster on large files. Signed-off-by: BIST pre-commit check
Presidio never uses spaCy's dependency parser and with only regex-based recognizers enabled the named entity recognizer did no useful work either. Disabling both roughly halves scan time with unchanged findings on test data. NER stays enabled if an NLP-based recognizer is re-enabled. Signed-off-by: BIST pre-commit check
The GitHub release check ran before the scans, delaying them by up to its 1-second timeout. Run it concurrently with the scans in run(), scheduled after them so proxy.py forks first. Signed-off-by: BIST pre-commit check
The release check was the only thing using aiohttp. Use urllib instead and remove aiohttp, its multidict pin, pytest-aiohttp and pytest-asyncio. This also saves about 0.06s per run_scan. Signed-off-by: BIST pre-commit check
Importing GitPython spawns a `git version` subprocess, although it is only used with --github-action. Defer the import so pre-commit scans skip it. Signed-off-by: BIST pre-commit check
joshwong-cs
force-pushed
the
perf/faster-hooks
branch
from
November 17, 2026 11:02
a277d18 to
3b846db
Compare
This was referenced Nov 17, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Note
AI-Assisted (Opus 5.5) with profiling, tests. Human proposed solutions and AI implementation (Sonnet 5.5).
Why it was slow
Other changes
This repo's own hooks now run in the published image. Commits here are scanned exactly like commits anywhere else, with the same trufflehog version and English model. Contributors no longer need trufflehog installed to commit and
make run-hook-pythonstill works for testing locally. The catch is that Python packages come from the image, so a PR that adds one fails these hooks. CONTRIBUTING explains how to build the image from your branch so you can still commit.The sign-off line is now added properly. The old code:
git commit -vand a custom comment characterNow git adds the line, and only if it isn't already there.
aiohttp is gone. The release check was the only thing using it so it now uses Python's built-in urllib. (something something supply chain risks)
Commits
--github-actionscansNoteworthy
-v, each amend adds another sign-off line. The PR check still passes.Type of change
How this has been tested
git commit -vand amends all pass.make build-dockerworks for the local hooks.Checklist
Reviewer Checklist