-
Notifications
You must be signed in to change notification settings - Fork 5
Add container-performance-choice opengrep rule for Chromium #862
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
| void BadExamples() { | ||
| // SHOULD TRIGGER: std::map for small/simple usage (consider base::flat_map) | ||
| // ruleid: chromium-std-map-performance-consideration | ||
| std::map<std::string, int> small_cache; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[opengrep] Consider using base::flat_map/base::flat_set instead of std::map/std::set
for small containers or write-once scenarios. Chromium guidelines suggest:
- Use base::flat_map for small collections (< ~100 elements)
- Use base::flat_map for write-once, read-many scenarios
- Only use std::map for large containers with frequent writes
- Use std::map if you need pointer stability
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/container-performance-choice.yaml
Cc @thypon @cdesouza-chromium
|
|
||
| // SHOULD TRIGGER: std::set for small collections (consider base::flat_set) | ||
| // ruleid: chromium-std-map-performance-consideration | ||
| std::set<int> small_ids; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[opengrep] Consider using base::flat_map/base::flat_set instead of std::map/std::set
for small containers or write-once scenarios. Chromium guidelines suggest:
- Use base::flat_map for small collections (< ~100 elements)
- Use base::flat_map for write-once, read-many scenarios
- Only use std::map for large containers with frequent writes
- Use std::map if you need pointer stability
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/container-performance-choice.yaml
Cc @thypon @cdesouza-chromium
|
|
||
| // SHOULD TRIGGER: std::multimap usage (consider alternatives) | ||
| // ruleid: chromium-std-map-performance-consideration | ||
| std::multimap<std::string, std::string> headers; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[opengrep] Consider using base::flat_map/base::flat_set instead of std::map/std::set
for small containers or write-once scenarios. Chromium guidelines suggest:
- Use base::flat_map for small collections (< ~100 elements)
- Use base::flat_map for write-once, read-many scenarios
- Only use std::map for large containers with frequent writes
- Use std::map if you need pointer stability
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/container-performance-choice.yaml
Cc @thypon @cdesouza-chromium
|
|
||
| // SHOULD TRIGGER: std::multiset usage (consider alternatives) | ||
| // ruleid: chromium-std-map-performance-consideration | ||
| std::multiset<int> duplicate_values; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[opengrep] Consider using base::flat_map/base::flat_set instead of std::map/std::set
for small containers or write-once scenarios. Chromium guidelines suggest:
- Use base::flat_map for small collections (< ~100 elements)
- Use base::flat_map for write-once, read-many scenarios
- Only use std::map for large containers with frequent writes
- Use std::map if you need pointer stability
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/container-performance-choice.yaml
Cc @thypon @cdesouza-chromium
| private: | ||
| // SHOULD TRIGGER: No justification for std::map usage | ||
| // ruleid: chromium-std-map-performance-consideration | ||
| std::map<std::string, bool> feature_flags_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[opengrep] Consider using base::flat_map/base::flat_set instead of std::map/std::set
for small containers or write-once scenarios. Chromium guidelines suggest:
- Use base::flat_map for small collections (< ~100 elements)
- Use base::flat_map for write-once, read-many scenarios
- Only use std::map for large containers with frequent writes
- Use std::map if you need pointer stability
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/container-performance-choice.yaml
Cc @thypon @cdesouza-chromium
|
|
||
| // SHOULD TRIGGER: std::map not ideal for write-once scenario | ||
| // ruleid: chromium-std-map-performance-consideration | ||
| std::map<std::string, int> limits; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reported by reviewdog 🐶
[opengrep] Consider using base::flat_map/base::flat_set instead of std::map/std::set
for small containers or write-once scenarios. Chromium guidelines suggest:
- Use base::flat_map for small collections (< ~100 elements)
- Use base::flat_map for write-once, read-many scenarios
- Only use std::map for large containers with frequent writes
- Use std::map if you need pointer stability
Source: https://github.com/brave/security-action/blob/main/assets/opengrep_rules/client/container-performance-choice.yaml
Cc @thypon @cdesouza-chromium
8f0a86a to
84a24a8
Compare
Suggest base::flat_map over std::map for better performance with small datasets, following Chromium performance guidelines.
84a24a8 to
47a35f0
Compare
Opengrep Findings📈 Comparison Results
Summary by Rule
Detailed Findings
|
Supersedes: #855