Performance
Composite Recipes
Recipes that include further recipes, often including the individual recipes below.
- Apply Kotlin performance idioms
- Collapse
filter \{ p \}.<terminal>()chains - Collapse
sorted().first/last()andreversed().first/last()chains - Find
Sequence/Listpipeline shape smells - Find collection construction inside loops
- Find expensive allocations inside collection lambdas
- Find expensive allocations on hot paths
- Improve performance of Kotlin code
- Use primitive
mutable<Int|Long|Float|Double>StateOfin Compose
Recipes
- Find
Base64.getDecoder()calls inside loops - Find
BigDecimal("...")allocations inside loops - Find
BigInteger("...")allocations inside loops - Find
BigInteger.valueOf(long)calls inside loops - Find
Calendar.getInstance()calls inside loops - Find
Charset.forName(...)calls inside loops - Find
Class.forNamecalls inside loops - Find
DateTimeFormatter.ofPatternallocations inside loops - Find
File(...).bufferedReader()calls inside loops - Find
Gson()allocations inside collection lambdas - Find
Gson()allocations inside loops - Find Jackson
ObjectMapper()allocations inside collection lambdas - Find Jackson
ObjectMapper()allocations inside loops - Find
Locale(...)allocations inside loops - Find
LoggerFactory.getLoggercalls inside collection lambdas - Find
LoggerFactory.getLoggercalls inside loops - Find
MessageDigest.getInstancecalls inside loops - Find
Optional.get()calls inside loops - Find
Pattern.compileallocations inside loops - Find
Pattern.compilecalls inside collection lambdas - Find
Regexallocations inside collection lambdas - Find
Regexallocations inside loops - Find
SimpleDateFormatallocations inside loops - Find
String.formatcalls inside collection lambdas - Find
String.formatcalls inside loops - Find
URI("...")allocations inside loops - Find
URL("...")allocations inside loops - Find
for (i in xs.indices) \{ val x = xs[i] \}patterns - Find graphics allocations inside
View.onDraw - Find graphics allocations inside
View.onLayout - Find graphics allocations inside
View.onMeasure - Find iteration-shape smells
- Find
listOf(...)calls inside loops - Find long
Listpipelines that should useSequence - Find
mutableListOf<T>()allocations inside loops - Find
mutableMapOf<K, V>()allocations inside loops - Find
s = s + "..."string concatenation inside loops - Find
seq.toList().map \{ ... \}patterns - Find string-allocation smells
- Use
any \{ predicate \}instead offilter \{ predicate \}.any() - Use
any \{ predicate \}instead offilter \{ predicate \}.isNotEmpty() - Use
count \{ predicate \}instead offilter \{ predicate \}.count() - Use
filterNotTo(mutableListOf(), p)instead offilterNot(p).toMutableList() - Use
filterTo(mutableListOf(), p)instead offilter(p).toMutableList() - Use
first \{ predicate \}instead offilter \{ predicate \}.first() - Use
first()instead ofreversed().last() - Use
firstNotNullOf \{ f \}instead ofmapNotNull \{ f \}.first() - Use
firstNotNullOfOrNull \{ f \}instead ofmapNotNull \{ f \}.firstOrNull() - Use
firstOrNull \{ predicate \}instead offilter \{ predicate \}.firstOrNull() - Use
flatMapTo(mutableListOf(), f)instead offlatMap(f).toMutableList() - Use
last \{ predicate \}instead offilter \{ predicate \}.last() - Use
last()instead ofreversed().first() - Use
lastOrNull \{ predicate \}instead offilter \{ predicate \}.lastOrNull() - Use
mapNotNull \{ f \}instead ofmap \{ f \}.filterNotNull() - Use
mapTo(mutableListOf(), f)instead ofmap(f).toMutableList() - Use
max()instead ofsorted().last() - Use
max()instead ofsortedDescending().first() - Use
maxBy \{ selector \}instead ofsortedBy \{ selector \}.last() - Use
maxOf \{ selector \}instead ofmap \{ selector \}.max() - Use
min()instead ofsorted().first() - Use
min()instead ofsortedDescending().last() - Use
minBy \{ selector \}instead ofsortedBy \{ selector \}.first() - Use
minOf \{ selector \}instead ofmap \{ selector \}.min() - Use
mutableDoubleStateOfinstead ofmutableStateOf<Double>in Compose - Use
mutableFloatStateOfinstead ofmutableStateOf<Float>in Compose - Use
mutableIntStateOfinstead ofmutableStateOf<Int>in Compose - Use
mutableLongStateOfinstead ofmutableStateOf<Long>in Compose - Use
none \{ predicate \}instead offilter \{ predicate \}.isEmpty() - Use
none \{ predicate \}instead offilter \{ predicate \}.none() - Use
sb.lengthinstead ofsb.toString().length - Use
single \{ predicate \}instead offilter \{ predicate \}.single() - Use
singleOrNull \{ predicate \}instead offilter \{ predicate \}.singleOrNull() - Use
sortedByDescending \{ f \}instead ofsortedBy \{ f \}.reversed() - Use
sortedDescending()instead ofsorted().reversed() - Use
sumOf \{ selector \}instead ofmap \{ selector \}.sum()