From ac51ba24cc69f18bdb787bb633b513b4c8a523d9 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 11 Feb 2025 19:30:47 +0100 Subject: [PATCH 1/7] Fix basic compilation of benchmarks --- buildSrc/build.gradle.kts | 2 +- gradle.properties | 1 + kotlinx-coroutines-core/build.gradle.kts | 7 +++++++ .../kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt | 2 +- .../channels/ChannelProducerConsumerBenchmark.kt | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 6d2efb6ea4..27b713684c 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -63,7 +63,7 @@ dependencies { exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7") exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib") } - implementation("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:0.4.9") + implementation("org.jetbrains.kotlinx:kotlinx-benchmark-plugin:${version("benchmarks")}") implementation("org.jetbrains.kotlinx:kotlinx-knit:${version("knit")}") implementation("org.jetbrains.kotlinx:atomicfu-gradle-plugin:${version("atomicfu")}") } diff --git a/gradle.properties b/gradle.properties index 67b17c995b..88ed14e7b8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,6 +4,7 @@ group=org.jetbrains.kotlinx kotlin_version=2.1.0 # DO NOT rename this property without adapting kotlinx.train build chain: atomicfu_version=0.26.1 +benchmarks_version=0.4.13 # Dependencies junit_version=4.12 diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index b01e96bd14..538a5beda4 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -58,6 +58,13 @@ kotlin { implementation("org.openjdk.jol:jol-core:0.16") } } + + create("jvmBenchmark") { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") + } + kotlin.srcDir("jvmBenchmark/kotlin") + } } /* * Configure two test runs for Native: diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt b/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt index 9fe895e88c..3135874578 100644 --- a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt +++ b/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt @@ -76,7 +76,7 @@ open class SemaphoreBenchmark { enum class SemaphoreBenchDispatcherCreator(val create: (parallelism: Int) -> CoroutineDispatcher) { FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }), - DEFAULT({ parallelism -> ExperimentalCoroutineDispatcher(corePoolSize = parallelism, maxPoolSize = parallelism) }) + DEFAULT({ parallelism -> CoroutineScheduler(corePoolSize = parallelism, maxPoolSize = parallelism).asCoroutineDispatcher() }) } private const val WORK_INSIDE = 50 diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt b/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt index e7d01bcbef..1e41e0bf63 100644 --- a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt +++ b/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt @@ -133,7 +133,7 @@ open class ChannelProducerConsumerBenchmark { enum class DispatcherCreator(val create: (parallelism: Int) -> CoroutineDispatcher) { FORK_JOIN({ parallelism -> ForkJoinPool(parallelism).asCoroutineDispatcher() }), - DEFAULT({ parallelism -> ExperimentalCoroutineDispatcher(corePoolSize = parallelism, maxPoolSize = parallelism) }) + DEFAULT({ parallelism -> CoroutineScheduler(corePoolSize = parallelism, maxPoolSize = parallelism).asCoroutineDispatcher() }) } enum class ChannelCreator(private val capacity: Int) { From a07767e40c99269ead9121db61a2d35b0649826d Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Wed, 12 Feb 2025 13:50:36 +0100 Subject: [PATCH 2/7] Multiplatform benchmark in core --- .../kotlin/SharedFlowBaseline.kt | 22 +++++++++ kotlinx-coroutines-core/build.gradle.kts | 48 +++++++++++++++---- 2 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt diff --git a/kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt b/kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt new file mode 100644 index 0000000000..833240b02c --- /dev/null +++ b/kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt @@ -0,0 +1,22 @@ +import kotlinx.coroutines.* +import kotlinx.coroutines.flow.* +import kotlinx.benchmark.* + +// Stresses out 'syncrhonozed' codepath in MutableSharedFlow +@State(Scope.Benchmark) +@Measurement(iterations = 3, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) +@OutputTimeUnit(BenchmarkTimeUnit.MICROSECONDS) +@BenchmarkMode(Mode.AverageTime) +open class SharedFlowBaseline { + private var size: Int = 10_000 + + @Benchmark + fun baseline() = runBlocking { + val flow = MutableSharedFlow() + launch { + repeat(size) { flow.emit(Unit) } + } + + flow.take(size).collect { } + } +} diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index 538a5beda4..f1b7ba1b54 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -59,12 +59,40 @@ kotlin { } } - create("jvmBenchmark") { + // Forgive me, Father, for I have sinned. + // Really, that is needed to have benchmark sourcesets be the part of the project, not a separate project + val benchmarkMain by creating { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") } + kotlin.srcDir("benchmarkMain/kotlin") + } + + create("jvmBenchmark") { kotlin.srcDir("jvmBenchmark/kotlin") } + + val bmm = sourceSets.getByName("benchmarkMain") + targets.matching { + it.name != "metadata" + // Doesn't work, don't want to figure it out for now + && !it.name.contains("wasm") + && !it.name.contains("js") + }.all { + compilations.create("benchmark") { + associateWith(this@all.compilations.getByName("main")) + defaultSourceSet { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") + } + dependsOn(bmm) + } + } + } + + targets.matching { it.name != "metadata" }.all { + benchmark.targets.register("${name}Benchmark") + } } /* * Configure two test runs for Native: @@ -91,13 +119,11 @@ kotlin { jvm { // For animal sniffer withJava() - compilations.create("benchmark") { associateWith(this@jvm.compilations.getByName("main")) } } } benchmark { targets { - register("jvmBenchmark") } } @@ -138,10 +164,12 @@ val allMetadataJar by tasks.getting(Jar::class) { setupManifest(this) } fun setupManifest(jar: Jar) { jar.manifest { - attributes(mapOf( - "Premain-Class" to "kotlinx.coroutines.debug.internal.AgentPremain", - "Can-Retransform-Classes" to "true", - )) + attributes( + mapOf( + "Premain-Class" to "kotlinx.coroutines.debug.internal.AgentPremain", + "Can-Retransform-Classes" to "true", + ) + ) } } @@ -194,9 +222,11 @@ fun Test.configureJvmForLincheck(segmentSize: Int = 1) { minHeapSize = "1g" maxHeapSize = "4g" // we may need more space for building an interleaving tree in the model checking mode // https://github.com/JetBrains/lincheck#java-9 - jvmArgs = listOf("--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED", // required for transformation + jvmArgs = listOf( + "--add-opens", "java.base/jdk.internal.misc=ALL-UNNAMED", // required for transformation "--add-exports", "java.base/sun.security.action=ALL-UNNAMED", - "--add-exports", "java.base/jdk.internal.util=ALL-UNNAMED") // in the model checking mode + "--add-exports", "java.base/jdk.internal.util=ALL-UNNAMED" + ) // in the model checking mode // Adjust internal algorithmic parameters to increase the testing quality instead of performance. systemProperty("kotlinx.coroutines.semaphore.segmentSize", segmentSize) systemProperty("kotlinx.coroutines.semaphore.maxSpinCycles", 1) // better for the model checking mode From d4ea35619349c19eda9eed7e35fef9930aeb7ebd Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Wed, 12 Feb 2025 13:56:18 +0100 Subject: [PATCH 3/7] ~regroup directories so it's nicer to look at --- .../jvm}/README.md | 0 .../kotlinx/coroutines/BenchmarkUtils.kt | 0 .../kotlinx/coroutines/SemaphoreBenchmark.kt | 0 .../ChannelProducerConsumerBenchmark.kt | 0 .../coroutines/channels/SelectBenchmark.kt | 0 .../coroutines/channels/SimpleChannel.kt | 0 .../channels/SimpleChannelBenchmark.kt | 0 .../coroutines/flow/TakeWhileBenchmark.kt | 0 .../main}/kotlin/SharedFlowBaseline.kt | 2 + kotlinx-coroutines-core/build.gradle.kts | 75 ++++++++++--------- 10 files changed, 40 insertions(+), 37 deletions(-) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/README.md (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/BenchmarkUtils.kt (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/channels/SelectBenchmark.kt (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/channels/SimpleChannel.kt (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/channels/SimpleChannelBenchmark.kt (100%) rename kotlinx-coroutines-core/{jvmBenchmark => benchmarks/jvm}/kotlin/kotlinx/coroutines/flow/TakeWhileBenchmark.kt (100%) rename kotlinx-coroutines-core/{benchmarkMain => benchmarks/main}/kotlin/SharedFlowBaseline.kt (95%) diff --git a/kotlinx-coroutines-core/jvmBenchmark/README.md b/kotlinx-coroutines-core/benchmarks/jvm/README.md similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/README.md rename to kotlinx-coroutines-core/benchmarks/jvm/README.md diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/BenchmarkUtils.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/BenchmarkUtils.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/BenchmarkUtils.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/BenchmarkUtils.kt diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/SemaphoreBenchmark.kt diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/ChannelProducerConsumerBenchmark.kt diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/SelectBenchmark.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/SelectBenchmark.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/SelectBenchmark.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/SelectBenchmark.kt diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/SimpleChannel.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/SimpleChannel.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/SimpleChannel.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/SimpleChannel.kt diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/SimpleChannelBenchmark.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/SimpleChannelBenchmark.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/channels/SimpleChannelBenchmark.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/channels/SimpleChannelBenchmark.kt diff --git a/kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/flow/TakeWhileBenchmark.kt b/kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/flow/TakeWhileBenchmark.kt similarity index 100% rename from kotlinx-coroutines-core/jvmBenchmark/kotlin/kotlinx/coroutines/flow/TakeWhileBenchmark.kt rename to kotlinx-coroutines-core/benchmarks/jvm/kotlin/kotlinx/coroutines/flow/TakeWhileBenchmark.kt diff --git a/kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt b/kotlinx-coroutines-core/benchmarks/main/kotlin/SharedFlowBaseline.kt similarity index 95% rename from kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt rename to kotlinx-coroutines-core/benchmarks/main/kotlin/SharedFlowBaseline.kt index 833240b02c..67ba1bf0c6 100644 --- a/kotlinx-coroutines-core/benchmarkMain/kotlin/SharedFlowBaseline.kt +++ b/kotlinx-coroutines-core/benchmarks/main/kotlin/SharedFlowBaseline.kt @@ -1,3 +1,5 @@ +package kotlinx.coroutines + import kotlinx.coroutines.* import kotlinx.coroutines.flow.* import kotlinx.benchmark.* diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index f1b7ba1b54..069c7bb6c7 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -1,5 +1,7 @@ import org.gradle.api.tasks.testing.* import org.gradle.kotlin.dsl.* +import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension +import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet import org.jetbrains.kotlin.gradle.plugin.mpp.* import org.jetbrains.kotlin.gradle.targets.native.tasks.* import org.jetbrains.kotlin.gradle.tasks.* @@ -58,41 +60,7 @@ kotlin { implementation("org.openjdk.jol:jol-core:0.16") } } - - // Forgive me, Father, for I have sinned. - // Really, that is needed to have benchmark sourcesets be the part of the project, not a separate project - val benchmarkMain by creating { - dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") - } - kotlin.srcDir("benchmarkMain/kotlin") - } - - create("jvmBenchmark") { - kotlin.srcDir("jvmBenchmark/kotlin") - } - - val bmm = sourceSets.getByName("benchmarkMain") - targets.matching { - it.name != "metadata" - // Doesn't work, don't want to figure it out for now - && !it.name.contains("wasm") - && !it.name.contains("js") - }.all { - compilations.create("benchmark") { - associateWith(this@all.compilations.getByName("main")) - defaultSourceSet { - dependencies { - implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") - } - dependsOn(bmm) - } - } - } - - targets.matching { it.name != "metadata" }.all { - benchmark.targets.register("${name}Benchmark") - } + setupBenchmarkSourceSets(this) } /* * Configure two test runs for Native: @@ -122,8 +90,41 @@ kotlin { } } -benchmark { - targets { +private fun KotlinMultiplatformExtension.setupBenchmarkSourceSets(ss: NamedDomainObjectContainer) { + // Forgive me, Father, for I have sinned. + // Really, that is needed to have benchmark sourcesets be the part of the project, not a separate project + @Suppress("UnusedVariable") + val benchmarkMain by ss.creating { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") + } + kotlin.srcDir("benchmarks/main/kotlin") + } + + ss.create("jvmBenchmark") { + kotlin.srcDir("benchmarks/jvm/kotlin") + } + + val bmm = sourceSets.getByName("benchmarkMain") + targets.matching { + it.name != "metadata" + // Doesn't work, don't want to figure it out for now + && !it.name.contains("wasm") + && !it.name.contains("js") + }.all { + compilations.create("benchmark") { + associateWith(this@all.compilations.getByName("main")) + defaultSourceSet { + dependencies { + implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") + } + dependsOn(bmm) + } + } + } + + targets.matching { it.name != "metadata" }.all { + benchmark.targets.register("${name}Benchmark") } } From 99c1a644bbfaf30f743d22b9096e1cebde01f9a5 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Wed, 12 Feb 2025 16:44:49 +0100 Subject: [PATCH 4/7] ~streamline configuration, add readme --- kotlinx-coroutines-core/benchmarks/README.md | 21 +++++++++++++++++++ .../benchmarks/jvm/README.md | 15 ------------- kotlinx-coroutines-core/build.gradle.kts | 11 ++++++---- 3 files changed, 28 insertions(+), 19 deletions(-) create mode 100644 kotlinx-coroutines-core/benchmarks/README.md delete mode 100644 kotlinx-coroutines-core/benchmarks/jvm/README.md diff --git a/kotlinx-coroutines-core/benchmarks/README.md b/kotlinx-coroutines-core/benchmarks/README.md new file mode 100644 index 0000000000..5ea19735b8 --- /dev/null +++ b/kotlinx-coroutines-core/benchmarks/README.md @@ -0,0 +1,21 @@ +## kotlinx-coroutines-core benchmarks + +Multiplatform benchmarks for kotlinx-coroutines-core. + +This source-set contains benchmarks that leverage `internal` API (e.g. `suspendCancellableCoroutineReusable`) or +that are multiplatform (-> only supported with `kotlinx-benchmarks` which is less convenient than `jmh` plugin). +For JVM-only non-internal benchmarks, consider using `benchmarks` top-level project. + +### Usage + +``` +// JVM only +./gradlew :kotlinx-coroutines-core:jvmBenchmarkBenchmarkJar +java -jar kotlinx-coroutines-core/build/benchmarks/jvmBenchmark/jars/kotlinx-coroutines-core-jvmBenchmark-jmh-*-JMH.jar + +// Native, OS X +./gradlew :kotlinx-coroutines-core:macosArm64BenchmarkBenchmark + +// Figure out what to use +./gradlew :kotlinx-coroutines-core:tasks | grep -i bench +``` diff --git a/kotlinx-coroutines-core/benchmarks/jvm/README.md b/kotlinx-coroutines-core/benchmarks/jvm/README.md deleted file mode 100644 index a89761a245..0000000000 --- a/kotlinx-coroutines-core/benchmarks/jvm/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## kotlinx-coroutines-core benchmarks - -This source-set contains benchmarks that leverage `internal` API (e.g. `suspendCancellableCoroutineReusable`) -and thus cannot be written in `benchmarks` module. - -This is an interim solution unless we introduce clear separation of responsibilities in benchmark modules -and decide on their usability. - - -### Usage - -``` -./gradlew :kotlinx-coroutines-core:jvmBenchmarkBenchmarkJar -java -jar kotlinx-coroutines-core/build/benchmarks/jvmBenchmark/jars/kotlinx-coroutines-core-jvmBenchmark-jmh-*-JMH.jar -``` diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index 069c7bb6c7..e4132a9fd8 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -60,8 +60,9 @@ kotlin { implementation("org.openjdk.jol:jol-core:0.16") } } - setupBenchmarkSourceSets(this) } + setupBenchmarkSourceSets(sourceSets) + /* * Configure two test runs for Native: * 1) Main thread @@ -98,14 +99,16 @@ private fun KotlinMultiplatformExtension.setupBenchmarkSourceSets(ss: NamedDomai dependencies { implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") } + // For each source set we have to manually set path to the sources, otherwise lookup will fail kotlin.srcDir("benchmarks/main/kotlin") } - ss.create("jvmBenchmark") { + @Suppress("UnusedVariable") + val jvmBenchmark by ss.creating { + // For each source set we have to manually set path to the sources, otherwise lookup will fail kotlin.srcDir("benchmarks/jvm/kotlin") } - val bmm = sourceSets.getByName("benchmarkMain") targets.matching { it.name != "metadata" // Doesn't work, don't want to figure it out for now @@ -118,7 +121,7 @@ private fun KotlinMultiplatformExtension.setupBenchmarkSourceSets(ss: NamedDomai dependencies { implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") } - dependsOn(bmm) + dependsOn(benchmarkMain) } } } From 0a389fd9774fa7af28706f6051a0b478ebfcb91e Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Wed, 12 Feb 2025 16:58:26 +0100 Subject: [PATCH 5/7] ~exclude benches sourceset from coverage --- kotlinx-coroutines-core/build.gradle.kts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index e4132a9fd8..47db3eb0c5 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -256,6 +256,9 @@ kover { // lincheck has NPE error on `ManagedStrategyStateHolder` class excludedClasses.addAll("org.jetbrains.kotlinx.lincheck.*") } + sources { + excludedSourceSets.addAll("benchmark") + } } reports { From 9ac96bbb41fa09f26c73fd006ccc80213bf9188b Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Wed, 12 Feb 2025 16:58:48 +0100 Subject: [PATCH 6/7] ~suppress --- kotlinx-coroutines-core/build.gradle.kts | 1 - 1 file changed, 1 deletion(-) diff --git a/kotlinx-coroutines-core/build.gradle.kts b/kotlinx-coroutines-core/build.gradle.kts index 47db3eb0c5..ce3250c150 100644 --- a/kotlinx-coroutines-core/build.gradle.kts +++ b/kotlinx-coroutines-core/build.gradle.kts @@ -94,7 +94,6 @@ kotlin { private fun KotlinMultiplatformExtension.setupBenchmarkSourceSets(ss: NamedDomainObjectContainer) { // Forgive me, Father, for I have sinned. // Really, that is needed to have benchmark sourcesets be the part of the project, not a separate project - @Suppress("UnusedVariable") val benchmarkMain by ss.creating { dependencies { implementation("org.jetbrains.kotlinx:kotlinx-benchmark-runtime:${version("benchmarks")}") From 1b9137e190e2046423b7e38d588b991843f80de2 Mon Sep 17 00:00:00 2001 From: Vsevolod Tolstopyatov Date: Tue, 18 Feb 2025 18:50:12 +0100 Subject: [PATCH 7/7] Update benchmarks version --- gradle.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/gradle.properties b/gradle.properties index 88ed14e7b8..88b96ac426 100644 --- a/gradle.properties +++ b/gradle.properties @@ -5,6 +5,7 @@ kotlin_version=2.1.0 # DO NOT rename this property without adapting kotlinx.train build chain: atomicfu_version=0.26.1 benchmarks_version=0.4.13 +benchmarks_jmh_version=1.37 # Dependencies junit_version=4.12