Add performance cops and resource matching helper#1046
Open
Add performance cops and resource matching helper#1046
Conversation
Signed-off-by: LohithR22 <lohithrgowda22@gmail.com>
|
jaymzh
reviewed
Jan 20, 2026
| module Cop | ||
| module Chef | ||
| module Performance | ||
| class RepeatedResourcesInLoops < Base |
Collaborator
There was a problem hiding this comment.
only the package resource actually supports arrays the way you're implying.
And there is already a cop for that, UseMultipackageInstalls.
jaymzh
requested changes
Jan 20, 2026
Collaborator
jaymzh
left a comment
There was a problem hiding this comment.
We picked one cop to review, we will come back and review others.
However, we encourage you to split up PRs into a single Cop each.
Collaborator
|
@LohithR22 are you still interested in working on this? |
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.



Description
This PR introduces multiple enhancements to Cookstyle focused on improving CPU and memory efficiency, as well as enhancing code maintainability through shared abstractions.
🚀 New Performance Cops Added
RepeatedResourcesInLoopsDetects creation of batchable Chef resources (e.g.,
package,user,service) inside Ruby loops (e.g.,.each), encouraging use of array resource declarations instead. This reduces unnecessary resource duplication and improves Chef client execution speed.LoadAllDataBagItemsFlags overly broad or empty
searchanddata_bag_searchqueries (e.g.,"*:*"or"") that can result in loading all data bag items into memory, causing high memory usage and increased IO. Promotes more selective querying to improve performance.🛠 Refactoring & Code Reuse
Introduced a shared helper module:
lib/rubocop/cop/chef/helpers/resource_matcher.rb, providing reusable AST detection methods:search_call?batchable_resource?includes_guard?node_is_chef_resource?Applied this helper in:
RepeatedResourcesInLoops,LoadAllDataBagItemsExecuteAptUpdateThis makes the cops cleaner, DRY, and more maintainable.
📚 Documentation
Added a performance cops documentation file under
docs-chef-cops/performance.mdwith:✅ Testing
ResourceMatcherhelper methods.Related Issue
No specific GitHub issue linked.
This PR adds new functionality and internal improvements targeting Chef client performance optimization in community cookbooks.
Types of Changes
Checklist
bundle exec rspecperformance.md,helpers.md)Gemfile.lockchanges exist.rubocop.ymlis valid