-
Notifications
You must be signed in to change notification settings - Fork 496
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve the performance of line regexes #244
Comments
To put the above differently, we ask "should we skip this line?" number of plugin times, where as we could ask once. @OiCMudkips pointed out it might make sense to skip 'em after secrets are found, I think they're right. Let's say the likelihood of having a line hit a |
This makes sense, so the allowed list can be checked once early in the process.
Sometimes we find a line might contain several secrets with different types. It would be nice not to skip a line after a secret been found, or give an option to control the behavior. |
I think we used to have, (my memory is super hazy about this), a really long time ago, an |
Hmm, to be clear, I meant that we should delay the whitelist check until after the secret is found. This means that we only run the whitelist check on # secrets found, instead of (# plugins)*(# lines). I agree that the |
This sounds like a really good idea to reduce some overhead given secret lines are rarer than normal lines. @OiCMudkips |
I can do this one, it's pretty easy. |
This fixes issue #244. Only check the line for allowlist regexes or --exclude-lines if a secret was found.
Due to the way we pass a file to every single plugin, rather than a line, we end up
regex.search
ing the same line P times, where P is the number of plugins. This holds true for bothALLOWLIST_REGEXES
and--exclude-lines
. For large diffs on a tightly provisioned box this can be quite inefficient.The relevant control flow is as follows
detect-secrets/detect_secrets/core/secrets_collection.py
Lines 336 to 341 in 5d3e065
detect-secrets/detect_secrets/plugins/base.py
Lines 45 to 57 in 5d3e065
detect-secrets/detect_secrets/plugins/base.py
Lines 81 to 97 in 5d3e065
The text was updated successfully, but these errors were encountered: