# Kotlin minOf() and maxOf() Can Allocate Arrays for Four or More Arguments

DevFeed: [Kotlin minOf() and maxOf() Can Allocate Arrays for Four or More Arguments](<https://devfeed.tech/articles/micro-optimizations-in-kotlin-3-25601.md>)

Original publisher: [Read original article](<https://www.romainguy.dev/posts/2024/micro-optimizations-in-kotlin-3/>)

Author: Romain Guy

Published: 2024-01-31T00:00:00Z

Content type: tutorial

Language: en

Sources: [Posts on Romain Guy](<https://devfeed.tech/sources/posts-on-romain-guy.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>), [Android](<https://devfeed.tech/topics/android.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [JIT](<https://devfeed.tech/topics/jit.md>), [Jetpack Compose](<https://devfeed.tech/topics/jetpack-compose.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [assembly](<https://devfeed.tech/tags/assembly.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [developer](<https://devfeed.tech/tags/developer.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [jit](<https://devfeed.tech/tags/jit.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [performance](<https://devfeed.tech/tags/performance.md>)

## AI overview

This article examines how Kotlin's minOf() and maxOf() handle four or more arguments on Android and the JVM. The variadic implementation can allocate an array at the call site, increasing execution time in tight loops; a four-parameter specialization removes those allocations in the discussed benchmarks.

## Source excerpt

The Kotlin standard library is a wonderful set of APIs, but it sometimes hides... interesting surprises. So today let's took at the innocent looking minOf() and maxOf() functions. These functions let you perform a min/max on a series of values, instead of just two with the more common min() and max() functions. Both min() and max() are straightforward and simply delegate -- on Android and JVM -- to Math.min()/Math.max() respectively, which you can assume to be implemented with intrinsics (and are on Android).