Paul Woitaschek
05/09/2022, 2:50 PMmbonnin
05/09/2022, 2:52 PMPaul Woitaschek
05/09/2022, 2:53 PMmbonnin
05/09/2022, 2:54 PMPaul Woitaschek
05/09/2022, 2:54 PMmbonnin
05/09/2022, 2:54 PMmbonnin
05/09/2022, 2:54 PMPaul Woitaschek
05/09/2022, 2:55 PMmbonnin
05/09/2022, 2:55 PMPaul Woitaschek
05/09/2022, 2:56 PMUUID
which was a NSUUID
.
By moving that to a regular data class the performance went up by 2x. I assume it’s something to do with overhead on calling into platform classes~Paul Woitaschek
05/09/2022, 2:57 PMfind
and distinct
mbonnin
05/09/2022, 2:58 PMPaul Woitaschek
05/09/2022, 2:58 PMPaul Woitaschek
05/09/2022, 2:58 PMpackage com.yazio.shared.uuid
import platform.Foundation.NSUUID
public actual data class UUID(val uuid: String) {
override fun toString(): String = uuid
}
public actual fun uuid(value: String): UUID {
return requireNotNull(value.asUUIDorNull()) {
"Could not parse $value"
}
}
public actual val UUID.value: String get() = uuid
public actual fun randomUUID(): UUID {
return NSUUID().toUUID()
}
public actual fun String.asUUIDorNull(): UUID? {
return try {
NSUUID(this)
} catch (e: NullPointerException) {
// Kotlin does not support optional initializers.
null
}?.toUUID()
}
private fun NSUUID.toUUID(): UUID {
return UUID(UUIDString.lowercase())
}
Paul Woitaschek
05/09/2022, 2:59 PMmbonnin
05/09/2022, 3:03 PMmbonnin
05/09/2022, 3:03 PMkpgalligan
05/09/2022, 8:21 PMPaul Woitaschek
05/09/2022, 9:52 PMkotlin took 1.959us
ns took 4.122052778s
~ilya.gorbunov
05/09/2022, 11:18 PMdarkmoon_uk
05/10/2022, 2:43 AM+
☝️ 🤦
Would be interested to see the result again using Kotlin 1.7.0 Beta, which 'headlines' with Native Memory Manager performance improvements 💪xxfast
05/10/2022, 3:56 AMPaul Woitaschek
05/10/2022, 4:50 AMdarkmoon_uk
05/10/2022, 6:20 AMrusshwolf
05/10/2022, 12:08 PMNSUUID
to get a UUIDString
to pass to the UUID
constructor. I wonder if that accounts for the 2x difference.