Rule Definition
Depending on the implementation of "forEach" custom tag, performance issues are at hand.
Benchmarks have shown that using "forEach" on a range can have a huge performance cost in comparison to simple for loops. Hence in most contexts a simple for loop should be used instead.
Remediation
Check if the use of "forEach" is well controlled, and use a simple for loop instead
Violation Code Sample
(1..10).forEach {
println(it)
}
(1 until 10).forEach {
println(it)
}
(10 downTo 1).forEach {
println(it)
}
Fixed Code Sample
for (i in 1..10) {
println(i)
}
Reference
https://sites.google.com/a/athaydes.com/renato-athaydes/posts/kotlinshiddencosts-benchmarks
Related Technologies
Technical Criterion
CWE-1050 - Excessive Platform Resource Consumption within a Loop
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.