Expensive Object In Loop (ARCH8072)
Key kotlin.performance.expensive-object-in-loop · Severity warning · Category performance
Flags SimpleDateFormat, ObjectMapper, Gson, DecimalFormat or MessageDigest constructed inside a loop body.
Incorrect
Section titled “Incorrect”for (r in rows) { val f = SimpleDateFormat("yyyy"); f.format(r.at) }Correct
Section titled “Correct”val f = SimpleDateFormat("yyyy")for (r in rows) f.format(r.at)Create the object once outside the loop (or as a property) and reuse it.