Rust

Rust

Made by DeepSource
Found occurrence of Arc<RwLock<HashMap<K, V>>> RS-P1003
Performance
Minor

Arc<RwLock<HashMap<K, V>>> has performance concerns, the dashmap crate provides a much better alternative to concurrent hashmaps. Hence, Arc<RwLock<HashMap<K, V>>> is better off replaced by Arc<DashMap<K, V>> from the dashmap crate.

Found usage of Box::new(T::default()) RS-P1008
Performance
Minor

Box::new(T::default()) is overly verbose, involving two function calls instead of one. It can be better written as Box::<T>::default().

Found manual implementation of retain() RS-P1009
Performance
Minor
Autofix

The collections in Rust (Vec, VecDeque, HashMap, HashSet, etc.) provide the retain(..) method to filter elements matching a given predicate and discard the rest. The drain(..) method can be used to do the reverse as well.

Consider using this instead of into_iter().filter().collect().

Audit required: Use of large enum variant RS-A1007
Performance
Major

Large size differences between enum variants can adversely impact performance, as the size of the enumeration is bounded by the largest variant. Having one very large variant can penalize the memory layout of the enum.

Found empty loop expression RS-P1000
Performance
Minor

These busy loops burn CPU cycles without doing anything. It is almost always a better idea to panic! than to have a busy loop.

Found occurrence of .bytes().count() RS-P1001
Performance
Minor

.bytes().count() is better written as .len() which is easier to read and more performant.

Found occurrence of .bytes().nth(..) RS-P1002
Performance
Minor

.bytes().nth(..) is better written as .as_bytes().get(..) which is more performant.

Found call to .trim() followed by .split_whitespace() RS-P1005
Performance
Minor

.split_whitespace() produces an iterator with preceding and trailing whitespace removed. Thus, s.trim().split_whitespace() is equivalent to just s.split_whitespace().

Unnecessary collect() on iterable to Vec RS-P1006
Performance
Minor
Autofix

Collecting Iterator to Vec has the possible cost of forcing allocation, hence instead directly using the iterator is more efficient quite often, if the Vec is unnecessary.

Found collapsible .replace(..) method calls RS-P1007
Performance
Minor

Multiple consecutive replace(..) calls with the same replacement text can result in poor performance. Oftentimes, these replace calls can be merged.

Found single-character string literal pattern RS-P1100
Performance
Major

Certain str functions, such as .split() and .find() work on patterns that accept both string literals as well as characters. When using such functions, prefer chars over single-character string literals as they are more performant.

Found trivial regex RS-W1027
Performance
Minor

Certain regexes that are used with Regex::new or RegexBuilder::new may be replaced by common str methods, such as str::starts_with, str::ends_with, str::contains and str::cmp.

Usage of expect followed by a function call RS-W1030
Performance
Minor

Calls to expect followed by a function call should be replaced with unwrap_or_else to increase laziness. The argument to expect is evaluated eagerly and unconditionally. The argument to unwrap_or_else is evaluated lazily and only if required, sometimes leading to lower overhead and fewer allocations.

Usage of unwrap_or followed by a function call RS-W1031
Performance
Minor

Calls to unwrap_or followed by a function call should be replaced with unwrap_or_else or unwrap_or_default, to increase laziness. The argument to unwrap_or is evaluated eagerly and unconditionally. unwrap_or_else or unwrap_or_default are evaluated lazily and only if required, sometimes leading to lower overhead and fewer allocations.

Needless iteration over collection that allows indexing RS-W1091
Performance
Major

Using .iter().nth(_) is a method of accessing the nth element of an iterable. However, some collections such as slices or VecDeques allow direct access to the nth element through helper methods such as get and get_mut (for mutable access). Not only are these methods more consise, they are also more performant.