Persist compiled rules locally rather than in-memory#1122
Merged
Conversation
Signed-off-by: egibs <20933572+egibs@users.noreply.github.com>
1b2afbb to
124fd1e
Compare
stevebeattie
approved these changes
Sep 11, 2025
stevebeattie
left a comment
Member
There was a problem hiding this comment.
Ooh, this is very nice! Thanks for this, it's very helpful for repetitive, investigative scans.
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.
We currently persist compiled rules in-memory which only works for the duration of a single
malinvocation. In cases where we want to run successivemalscans (usually when looping over specific files or directories to produce per-scan result files), we run into rule compilation overhead which takes at least several seconds per run which can be extremely slow when done dozens of times.This PR instead stores rules locally in the user's cache directory using the compiled rule hash. This file is read from each time
malis run and will only be recreated if it does not exist.I also added tests and benchmarks so we can validate this works and is faster (which it is by a factor of 10-12x):
BenchmarkRecursivetakes ~4.6 seconds whereasBenchmarkRecursiveCachedSubsequentRunstakes ~.32 seconds.