-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Enable caching for collecting rules #3796
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
base: main
Are you sure you want to change the base?
Conversation
Generated by 🚫 Danger |
c103343 to
5001b15
Compare
|
@jpsim Would appreciate some feedback, so I can understand if this is something you would accept |
|
Thanks for the PR and the discussion! I think this is an important optimization to make analyzer rules significantly more useful. Were you able to measure a significant performance improvement on a real world codebase? I think it's important to be able to measure if this is having the expected impact you want. |
|
Also if you rebase, hopefully OSSCheck will produce more reasonable results than what's currently posted above. Not that it matters much for this PR since OSSCheck doesn't run any analyzer rules. |
5001b15 to
a2ee0e9
Compare
I did not start using this on a real world codebase yet. Will do that and come back with an answer |
|
Thanks! I wonder if caching the result of |
Mmm 🤔Seems like if file did not change (and |
6a1f212 to
62be901
Compare
Hi 👋
This PR enables caching for collecting rules
Main idea
The collection step required by collecting rules is usually a very time consuming process. Under some scenarios and making some assumptions, the result of such computation can be cached
Implementation details:
FileInfotype toCollectingCachableCollectingCachableis makingFileInfoconform toCodable. If that is undesired, then creating a middleware Dto is also possibleDiscussion
As an example, I enabled caching for the two collecting rules in the codebase:
UnusedDeclarationRuleandCaptureVariableRule. Both rules querySourceKitServiceduring collection. The main assumption that allows caching is that if a swift file and its compiler arguments do not change => the values returned bySourceKitServicedo not change either, and can be cached and reused between SwiftLint executions.This is specially useful for the
UnusedDeclarationRule, as the process of removing all unused declarations is iterative: removing flagged unused declarations will uncover new unused declarations. In a big codebase whereUnusedDeclarationRuletakes long time to execute, caching the collection information dramatically speeds up the code removal process