Add container-performance-choice opengrep rule for Chromium#862
Add container-performance-choice opengrep rule for Chromium#862
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.
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.
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.
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.
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.
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.
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