From 773279c1aa949e53d852298a2b9c5cc2087c37f6 Mon Sep 17 00:00:00 2001 From: Nek-12 Date: Sun, 8 Dec 2024 15:06:26 +0100 Subject: [PATCH] chore: fix benchmarks --- benchmarks/build.gradle.kts | 3 ++- .../jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt | 4 ++-- .../flowmvi/benchmarks/setup/atomic/AtomicFMVIBenchmark.kt | 2 +- .../respawn/flowmvi/benchmarks/setup/atomic/AtomicStore.kt | 5 +++-- .../flowmvi/benchmarks/setup/fluxo/FluxoIntentBenchmark.kt | 2 ++ .../flowmvi/benchmarks/setup/optimized/OptimizedStore.kt | 4 ++-- 6 files changed, 12 insertions(+), 8 deletions(-) diff --git a/benchmarks/build.gradle.kts b/benchmarks/build.gradle.kts index 3d9a0100..58856dc3 100644 --- a/benchmarks/build.gradle.kts +++ b/benchmarks/build.gradle.kts @@ -25,6 +25,7 @@ kotlin { tvOs = false, windows = false, wasmJs = false, + jvm = true, ) } tasks.withType().configureEach { @@ -47,7 +48,7 @@ benchmark { named("main") { iterations = 100 warmups = 20 - iterationTime = 100 + iterationTime = 500 iterationTimeUnit = "ms" outputTimeUnit = "us" mode = "avgt" // "thrpt" - throughput, "avgt" - average diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt index 97ab9eb1..bf543844 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/Main.kt @@ -6,14 +6,14 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import kotlinx.coroutines.yield import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment -import pro.respawn.flowmvi.benchmarks.setup.atomic.atomicParallelStore +import pro.respawn.flowmvi.benchmarks.setup.atomic.atomicStore /** * run an infinite process for profiling */ fun main() = runBlocking { println(ProcessHandle.current().pid()) - val store = atomicParallelStore(this) + val store = atomicStore(this) launch { while (isActive) { store.intent(Increment) diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicFMVIBenchmark.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicFMVIBenchmark.kt index 5c92deb8..3b8dd2f4 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicFMVIBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicFMVIBenchmark.kt @@ -17,7 +17,7 @@ internal class AtomicFMVIBenchmark { @Benchmark fun benchmark() = runBlocking { - val store = atomicParallelStore(this) + val store = atomicStore(this) repeat(BenchmarkDefaults.intentsPerIteration) { store.emit(BenchmarkIntent.Increment) } diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicStore.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicStore.kt index 4930c2ab..259d6edb 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicStore.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/atomic/AtomicStore.kt @@ -4,6 +4,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.Channel import pro.respawn.flowmvi.api.ActionShareBehavior +import pro.respawn.flowmvi.api.StateStrategy import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState @@ -15,14 +16,14 @@ private fun StoreBuilder<*, *, *>.config() = configure { logger = null debuggable = false actionShareBehavior = ActionShareBehavior.Disabled - atomicStateUpdates = true + stateStrategy = StateStrategy.Atomic(reentrant = false) parallelIntents = false verifyPlugins = false onOverflow = BufferOverflow.SUSPEND intentCapacity = Channel.UNLIMITED } -internal fun atomicParallelStore( +internal fun atomicStore( scope: CoroutineScope ) = store(BenchmarkState(), scope) { config() diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoIntentBenchmark.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoIntentBenchmark.kt index 66a0f41c..61ad16cb 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoIntentBenchmark.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/fluxo/FluxoIntentBenchmark.kt @@ -2,6 +2,7 @@ package pro.respawn.flowmvi.benchmarks.setup.fluxo import kotlinx.coroutines.flow.first import kotlinx.coroutines.runBlocking +import kt.fluxo.core.annotation.ExperimentalFluxoApi import kt.fluxo.core.closeAndWait import org.openjdk.jmh.annotations.Benchmark import org.openjdk.jmh.annotations.Scope @@ -15,6 +16,7 @@ import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent @State(Scope.Benchmark) internal class FluxoIntentBenchmark { + @OptIn(ExperimentalFluxoApi::class) @Benchmark fun benchmark() = runBlocking { val store = fluxoStore() diff --git a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/optimized/OptimizedStore.kt b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/optimized/OptimizedStore.kt index 5dfdebc5..73415de1 100644 --- a/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/optimized/OptimizedStore.kt +++ b/benchmarks/src/jvmMain/kotlin/pro/respawn/flowmvi/benchmarks/setup/optimized/OptimizedStore.kt @@ -4,13 +4,13 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.channels.BufferOverflow import kotlinx.coroutines.channels.Channel import pro.respawn.flowmvi.api.ActionShareBehavior.Disabled +import pro.respawn.flowmvi.api.StateStrategy.Immediate import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent import pro.respawn.flowmvi.benchmarks.setup.BenchmarkIntent.Increment import pro.respawn.flowmvi.benchmarks.setup.BenchmarkState import pro.respawn.flowmvi.dsl.StoreBuilder import pro.respawn.flowmvi.dsl.store import pro.respawn.flowmvi.dsl.updateStateImmediate -import pro.respawn.flowmvi.plugins.reduce import pro.respawn.flowmvi.plugins.reducePlugin internal fun StoreBuilder<*, *, *>.config() { @@ -18,7 +18,7 @@ internal fun StoreBuilder<*, *, *>.config() { logger = null debuggable = false actionShareBehavior = Disabled - atomicStateUpdates = false + stateStrategy = Immediate parallelIntents = false verifyPlugins = false onOverflow = BufferOverflow.SUSPEND