# Speeding up isBlank()

DevFeed: [Speeding up isBlank()](<https://devfeed.tech/articles/speeding-up-isblank-25606.md>)

Original publisher: [Read original article](<https://www.romainguy.dev/posts/2024/speeding-up-isblank/>)

Author: Romain Guy

Published: 2024-02-05T00:00:00Z

Content type: tutorial

Language: en

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

Topics: [Compose](<https://devfeed.tech/topics/compose.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Benchmark](<https://devfeed.tech/topics/benchmark.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [assembly](<https://devfeed.tech/tags/assembly.md>), [benchmark](<https://devfeed.tech/tags/benchmark.md>), [benchmarks](<https://devfeed.tech/tags/benchmarks.md>), [compilation](<https://devfeed.tech/tags/compilation.md>), [compose](<https://devfeed.tech/tags/compose.md>), [developer](<https://devfeed.tech/tags/developer.md>), [graphics](<https://devfeed.tech/tags/graphics.md>), [jetpack-compose](<https://devfeed.tech/tags/jetpack-compose.md>), [jvm](<https://devfeed.tech/tags/jvm.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [performance](<https://devfeed.tech/tags/performance.md>)

## AI overview

This article examines the JVM bytecode generated for Kotlin's isBlank() implementation and shows how replacing its generic iteration with traditional loops can improve performance. In benchmarks using 1,000 strings, the revised implementation is reported as 60% faster with zero allocations, while a further optimization reaches nearly 65% faster than the original. The final version also reduces ARM assembly instructions from 161 to 53, illustrating how simple abstractions can affect performance in some workloads.

## Source excerpt

I was recently optimizing a small part of the Jetpack Compose runtime when I stumbled upon a seemingly harmless API, isBlank(). This API return true if the string it's called on is empty or consists solely of whitespace characters. But is it truly harmless? Let's look at the JVM implementation to get a better sense of what it does: 1public actual fun CharSequence.isBlank(): Boolean = 2 length == 0 || indices.all { this[it].isWhitespace() } Simple and straight to the point. Unfortunately the bytecode tells a very different story: