Repository navigation
Make the pre-commit hooks about twice as fast and fix the sign-off line - #282
joshwong-cs wants to merge 9 commits into
Conversation
|
Your PR has commits that are missing the Signed-off-by trailer, which is added by the pre-commit hooks. To install them, run |
1 similar comment
|
Your PR has commits that are missing the Signed-off-by trailer, which is added by the pre-commit hooks. To install them, run |
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
a277d18 to
3b846db
Compare
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