From 09d26a14d19bddb5a87aaa34e7f9e5562ffa2852 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 23 Dec 2024 16:35:56 +0100 Subject: [PATCH 1/5] chore: update kotlin to 2.1.0 --- .gitignore | 4 ++++ buildSrc/src/main/kotlin/Dependencies.kt | 6 +++--- gradle.properties | 1 + gradle/wrapper/gradle-wrapper.properties | 2 +- serialization-msgpack/build.gradle.kts | 7 ++++++- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 256f2f8..3e49fef 100644 --- a/.gitignore +++ b/.gitignore @@ -110,5 +110,9 @@ gradle-app.setting # Cache of project .gradletasknamecache + +.classpath +.project +.settings .kotlin kotlin-js-store/ diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index b3c8cdb..a8350a5 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -1,9 +1,9 @@ object Dependencies { object Versions { - const val kotlin = "2.0.20" + const val kotlin = "2.1.0" const val serialization = "1.7.3" const val datetime = "0.6.1" - const val ktlintGradle = "12.1.1" - const val dokkaGradle = "1.9.20" + const val ktlintGradle = "12.1.2" + const val dokkaGradle = "2.0.0" } } diff --git a/gradle.properties b/gradle.properties index 9d70e55..cdd0da8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,7 @@ kotlin.code.style=official kotlin.incremental.multiplatform=true kotlin.js.generate.executable.default=false +kotlin.js.compiler=both kotlin.native.ignoreDisabledTargets=true org.gradle.vfs.watch=true diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d642e7f..81aa1c0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/serialization-msgpack/build.gradle.kts b/serialization-msgpack/build.gradle.kts index 07796b7..5b0c82c 100644 --- a/serialization-msgpack/build.gradle.kts +++ b/serialization-msgpack/build.gradle.kts @@ -7,6 +7,11 @@ plugins { } kotlin { + jvm { + compilations.all { + kotlinOptions.jvmTarget = "1.8" + } + } js { browser { testTask { @@ -18,8 +23,8 @@ kotlin { } applyDefaultHierarchyTemplate() jvm() - iosX64() iosArm64() + iosX64() iosSimulatorArm64() tvosX64() tvosArm64() From 8f8a40b76cf929f167e42a7895414065e3aa0587 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 23 Dec 2024 17:42:37 +0100 Subject: [PATCH 2/5] test: add basic serialization benchmark --- build.gradle.kts | 1 + buildSrc/src/main/kotlin/Dependencies.kt | 1 + .../build.gradle.kts | 24 ++++++- .../build.gradle.kts | 23 +++++- serialization-msgpack/build.gradle.kts | 19 ++++- .../kotlinx/serialization/msgpack/TestData.kt | 56 +++++++++++---- .../SerializeBenchmarks.kt | 71 +++++++++++++++++++ 7 files changed, 173 insertions(+), 22 deletions(-) create mode 100644 serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt diff --git a/build.gradle.kts b/build.gradle.kts index 8be6e3e..baf2766 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,6 +1,7 @@ plugins { kotlin("multiplatform") version Dependencies.Versions.kotlin apply false kotlin("plugin.serialization") version Dependencies.Versions.kotlin apply false + id("org.jetbrains.kotlinx.benchmark") version Dependencies.Versions.benchmark apply false } repositories { diff --git a/buildSrc/src/main/kotlin/Dependencies.kt b/buildSrc/src/main/kotlin/Dependencies.kt index a8350a5..822876a 100644 --- a/buildSrc/src/main/kotlin/Dependencies.kt +++ b/buildSrc/src/main/kotlin/Dependencies.kt @@ -5,5 +5,6 @@ object Dependencies { const val datetime = "0.6.1" const val ktlintGradle = "12.1.2" const val dokkaGradle = "2.0.0" + const val benchmark = "0.4.13" } } diff --git a/serialization-msgpack-timestamp-extension/build.gradle.kts b/serialization-msgpack-timestamp-extension/build.gradle.kts index f520b0f..2d4893e 100644 --- a/serialization-msgpack-timestamp-extension/build.gradle.kts +++ b/serialization-msgpack-timestamp-extension/build.gradle.kts @@ -1,13 +1,21 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("maven-publish") id("signing") id("org.jetbrains.dokka") + id("org.jetbrains.kotlinx.benchmark") } kotlin { - jvm() + applyDefaultHierarchyTemplate() + jvm { + compilations.create("benchmark") { + associateWith(this@jvm.compilations.getByName("main")) + } + } js { browser { testTask { @@ -17,10 +25,9 @@ kotlin { } } } - applyDefaultHierarchyTemplate() - jvm() iosX64() iosArm64() + iosX64() iosSimulatorArm64() tvosX64() tvosArm64() @@ -61,6 +68,11 @@ kotlin { implementation(kotlin("test-junit")) } } + jvmBenchmark { + dependencies { + implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) + } + } jsTest { dependencies { implementation(kotlin("test-js")) @@ -68,3 +80,9 @@ kotlin { } } } + +benchmark { + targets { + register("jvmBenchmark") + } +} diff --git a/serialization-msgpack-unsigned-support/build.gradle.kts b/serialization-msgpack-unsigned-support/build.gradle.kts index 1302789..47c5608 100644 --- a/serialization-msgpack-unsigned-support/build.gradle.kts +++ b/serialization-msgpack-unsigned-support/build.gradle.kts @@ -1,13 +1,20 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("maven-publish") id("signing") id("org.jetbrains.dokka") + id("org.jetbrains.kotlinx.benchmark") } kotlin { - jvm() + jvm { + compilations.create("benchmark") { + associateWith(this@jvm.compilations.getByName("main")) + } + } js { browser { testTask { @@ -18,9 +25,8 @@ kotlin { } } applyDefaultHierarchyTemplate() - jvm() - iosX64() iosArm64() + iosX64() iosSimulatorArm64() tvosX64() tvosArm64() @@ -60,6 +66,11 @@ kotlin { implementation(kotlin("test-junit")) } } + jvmBenchmark { + dependencies { + implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) + } + } jsTest { dependencies { implementation(kotlin("test-js")) @@ -67,3 +78,9 @@ kotlin { } } } + +benchmark { + targets { + register("jvmBenchmark") + } +} diff --git a/serialization-msgpack/build.gradle.kts b/serialization-msgpack/build.gradle.kts index 5b0c82c..61beb7e 100644 --- a/serialization-msgpack/build.gradle.kts +++ b/serialization-msgpack/build.gradle.kts @@ -1,15 +1,18 @@ +import org.jetbrains.kotlin.gradle.dsl.JvmTarget + plugins { kotlin("multiplatform") kotlin("plugin.serialization") id("maven-publish") id("signing") id("org.jetbrains.dokka") + id("org.jetbrains.kotlinx.benchmark") } kotlin { jvm { - compilations.all { - kotlinOptions.jvmTarget = "1.8" + compilations.create("benchmark") { + associateWith(this@jvm.compilations.getByName("main")) } } js { @@ -22,7 +25,6 @@ kotlin { } } applyDefaultHierarchyTemplate() - jvm() iosArm64() iosX64() iosSimulatorArm64() @@ -64,6 +66,11 @@ kotlin { implementation(kotlin("test-junit")) } } + jvmBenchmark { + dependencies { + implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) + } + } jsTest { dependencies { implementation(kotlin("test-js")) @@ -71,3 +78,9 @@ kotlin { } } } + +benchmark { + targets { + register("jvmBenchmark") + } +} diff --git a/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt b/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt index 3ca9d51..68b3379 100644 --- a/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt +++ b/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt @@ -1,4 +1,3 @@ -@file:Suppress("ktlint") package com.ensarsarajcic.kotlinx.serialization.msgpack import com.ensarsarajcic.kotlinx.serialization.msgpack.extensions.BaseMsgPackExtensionSerializer @@ -90,25 +89,46 @@ object TestData { "a474657374" to "test", "a82d31323377686174" to "-123what", "a82d31323377686174" to "-123what", - "bf74657374747474747474747474747474747474747474747474747474747474" to "testttttttttttttttttttttttttttt", // Max fixStr size - "aac48dc487c48dc487c2bc" to "čćčć¼", // UTF-8 support + // Max fixStr size + "bf74657374747474747474747474747474747474747474747474747474747474" to "testttttttttttttttttttttttttttt", + // UTF-8 support + "aac48dc487c48dc487c2bc" to "čćčć¼", ) val str8TestPairs = arrayOf( - "d9207465737474747474747474747474747474747474747474747474747474747474" to "testtttttttttttttttttttttttttttt", // Min Str8 size - "d92a7465737474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" to "testttttttttttttttttttttttttttttčćčć¼", // UTF-8 support - "d9ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", // Max Str8 size + // Min Str8 size + "d9207465737474747474747474747474747474747474747474747474747474747474" to "testtttttttttttttttttttttttttttt", + // UTF-8 support + "d92a7465737474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" to + "testttttttttttttttttttttttttttttčćčć¼", + // Max Str8 size + @Suppress("ktlint:standard:max-line-length") + "d9ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" + to + "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", ) val str16TestPairs = arrayOf( - "da010074657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to "testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", // Min Str16 size - "da010a74657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" to "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttčćčć¼", // UTF-8 support + // Min Str16 size + @Suppress("ktlint:standard:max-line-length") + "da010074657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" + to "testtttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt", + // UTF-8 support + @Suppress("ktlint:standard:max-line-length") + "da010a74657374747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474c48dc487c48dc487c2bc" + to "testttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttčćčć¼", ) val bin8TestPairs = arrayOf( "c409010203040506070809" to byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9), "c400" to byteArrayOf(), - "c4ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to byteArrayOf(116, 101, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116), + @Suppress("ktlint:standard:max-line-length") + "c4ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" + to + @Suppress("ktlint:standard:max-line-length") + byteArrayOf( + 116, 101, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, + ), ) val intArrayTestPairs = arrayOf( @@ -118,7 +138,8 @@ object TestData { val stringArrayTestPairs = arrayOf( "92a3616263a3646566" to arrayOf("abc", "def"), - "92d921616266647366736466736466647366736466736673646673647364666466646663a3616473" to arrayOf("abfdsfsdfsdfdsfsdfsfsdfsdsdfdfdfc", "ads"), + "92d921616266647366736466736466647366736466736673646673647364666466646663a3616473" to + arrayOf("abfdsfsdfsdfdsfsdfsfsdfsdsdfdfdfc", "ads"), ) val mixedListTestPairs = arrayOf( @@ -203,7 +224,10 @@ object TestData { ) val unknownKeysTestPairs = arrayOf( - "85aa74657374537472696e67a3646566ab7465737449676e6f72656491a969676e6f7265206d65a774657374496e747bab74657374556e6b6e6f776ea7756e6b6e6f776eab74657374426f6f6c65616ec3" to SampleClass("def", 123, true), + @Suppress("ktlint:standard:max-line-length") + "85aa74657374537472696e67a3646566ab7465737449676e6f72656491a969676e6f7265206d65a774657374496e747bab74657374556e6b6e6f776ea7756e6b6e6f776eab74657374426f6f6c65616ec3" + to + SampleClass("def", 123, true), ) val floatEncodedDataTestPairs = @@ -221,8 +245,14 @@ object TestData { ) val nestedSampleClassWithMissingValue = arrayOf( - "84aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656482aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3" to SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null)), - "85aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656483aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3ae616e6f74686572556e6b6e6f776ea474657374ac7365636f6e644e657374656481ab74657374426f6f6c65616ec2" to SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null), SampleClassWithNestedClass.NestedClass(null)), + @Suppress("ktlint:standard:max-line-length") + "84aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656482aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3" + to + SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null)), + @Suppress("ktlint:standard:max-line-length") + "85aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656483aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3ae616e6f74686572556e6b6e6f776ea474657374ac7365636f6e644e657374656481ab74657374426f6f6c65616ec2" + to + SampleClassWithNestedClass("def", 123, true, SampleClassWithNestedClass.NestedClass(null), SampleClassWithNestedClass.NestedClass(null)), ) } diff --git a/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt new file mode 100644 index 0000000..addd13e --- /dev/null +++ b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/SerializeBenchmarks.kt @@ -0,0 +1,71 @@ +package com.ensarsarajcic.kotlinx.serialization.msgpack + +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.BenchmarkMode +import kotlinx.benchmark.BenchmarkTimeUnit +import kotlinx.benchmark.Measurement +import kotlinx.benchmark.Mode +import kotlinx.benchmark.OutputTimeUnit +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable +import kotlinx.serialization.encodeToByteArray + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) +@Measurement(iterations = 20, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) +@State(Scope.Benchmark) +open class SerializeBenchmarks { + @Serializable + data class SampleClass( + @SerialName("testString") + val testString: String, + val testInt: Int, + val testBoolean: Boolean, + ) + + @Serializable + data class SampleClassWithNestedClass( + val testString: String, + val testInt: Int, + val testBoolean: Boolean, + val testNested: NestedClass, + val testSample: SampleClass, + val testSampleList: List, + val testSampleMap: Map, + val extraBytes: ByteArray, + val secondNested: NestedClass? = null, + ) { + @Serializable + data class NestedClass( + val testInt: Int? = null, + ) + } + + // The actual benchmark method + @Benchmark + fun benchmarkMethod() { + val instance = + SampleClassWithNestedClass( + testString = "testString", + testInt = 10, + testBoolean = true, + testNested = SampleClassWithNestedClass.NestedClass(5), + testSample = SampleClass(testString = "testString2", testInt = 17, testBoolean = false), + testSampleList = + listOf( + SampleClass("testString3", testInt = 25, testBoolean = true), + SampleClass("testString4", testInt = 100, testBoolean = false), + ), + testSampleMap = + mapOf( + "testString5" to SampleClass("testString5", testInt = 12, testBoolean = false), + "testString6" to SampleClass("testString6", testInt = 15, testBoolean = true), + ), + extraBytes = byteArrayOf(0x12, 0x13, 0x14, 0x15), + secondNested = SampleClassWithNestedClass.NestedClass(null), + ) + MsgPack.encodeToByteArray(instance) + } +} From 1c7b461cbb16541d961cad833775837ecf485c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 23 Dec 2024 17:50:21 +0100 Subject: [PATCH 3/5] feat: add basic deserialization benchmark --- .../build.gradle.kts | 4 +- .../build.gradle.kts | 4 +- serialization-msgpack/build.gradle.kts | 4 +- .../DeserializeBenchmarks.kt | 50 +++++++++++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt diff --git a/serialization-msgpack-timestamp-extension/build.gradle.kts b/serialization-msgpack-timestamp-extension/build.gradle.kts index 2d4893e..5f6bb76 100644 --- a/serialization-msgpack-timestamp-extension/build.gradle.kts +++ b/serialization-msgpack-timestamp-extension/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - plugins { kotlin("multiplatform") kotlin("plugin.serialization") @@ -68,7 +66,7 @@ kotlin { implementation(kotlin("test-junit")) } } - jvmBenchmark { + val jvmBenchmark by getting { dependencies { implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) } diff --git a/serialization-msgpack-unsigned-support/build.gradle.kts b/serialization-msgpack-unsigned-support/build.gradle.kts index 47c5608..22aafee 100644 --- a/serialization-msgpack-unsigned-support/build.gradle.kts +++ b/serialization-msgpack-unsigned-support/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - plugins { kotlin("multiplatform") kotlin("plugin.serialization") @@ -66,7 +64,7 @@ kotlin { implementation(kotlin("test-junit")) } } - jvmBenchmark { + val jvmBenchmark by getting { dependencies { implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) } diff --git a/serialization-msgpack/build.gradle.kts b/serialization-msgpack/build.gradle.kts index 61beb7e..a968680 100644 --- a/serialization-msgpack/build.gradle.kts +++ b/serialization-msgpack/build.gradle.kts @@ -1,5 +1,3 @@ -import org.jetbrains.kotlin.gradle.dsl.JvmTarget - plugins { kotlin("multiplatform") kotlin("plugin.serialization") @@ -66,7 +64,7 @@ kotlin { implementation(kotlin("test-junit")) } } - jvmBenchmark { + val jvmBenchmark by getting { dependencies { implementation(kotlinx("benchmark-runtime", Dependencies.Versions.benchmark)) } diff --git a/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt new file mode 100644 index 0000000..1ff5aac --- /dev/null +++ b/serialization-msgpack/src/jvmBenchmark/kotlin/com.ensarsarajcic.kotlinx.serialization.msgpack/DeserializeBenchmarks.kt @@ -0,0 +1,50 @@ +package com.ensarsarajcic.kotlinx.serialization.msgpack + +import com.ensarsarajcic.kotlinx.serialization.msgpack.internal.BasicMsgPackDecoder +import com.ensarsarajcic.kotlinx.serialization.msgpack.stream.toMsgPackBuffer +import kotlinx.benchmark.Benchmark +import kotlinx.benchmark.BenchmarkMode +import kotlinx.benchmark.BenchmarkTimeUnit +import kotlinx.benchmark.Measurement +import kotlinx.benchmark.Mode +import kotlinx.benchmark.OutputTimeUnit +import kotlinx.benchmark.Scope +import kotlinx.benchmark.State +import kotlinx.serialization.Serializable +import kotlinx.serialization.modules.SerializersModule + +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(BenchmarkTimeUnit.NANOSECONDS) +@Measurement(iterations = 20, time = 1, timeUnit = BenchmarkTimeUnit.SECONDS) +@State(Scope.Benchmark) +open class DeserializeBenchmarks { + @Serializable + data class SampleClassWithNestedClass( + val testString: String, + val testInt: Int, + val testBoolean: Boolean, + val testNested: NestedClass, + val secondNested: NestedClass? = null, + ) { + @Serializable + data class NestedClass( + val testInt: Int? = null, + ) + } + + // The actual benchmark method + @Benchmark + fun benchmarkMethod() { + val decoder = + BasicMsgPackDecoder( + MsgPackConfiguration.default.copy(ignoreUnknownKeys = true), + SerializersModule { + }, + @Suppress("ktlint:standard:max-line-length") + "85aa74657374537472696e67a3646566a774657374496e747bab74657374426f6f6c65616ec3aa746573744e657374656483aa74657374537472696e67a3646566ab74657374426f6f6c65616ec3ae616e6f74686572556e6b6e6f776ea474657374ac7365636f6e644e657374656481ab74657374426f6f6c65616ec2".hexStringToByteArray().toMsgPackBuffer(), + ) + SampleClassWithNestedClass.serializer().deserialize(decoder) + } +} + +fun String.hexStringToByteArray() = ByteArray(this.length / 2) { this.substring(it * 2, it * 2 + 2).toInt(16).toByte() } From 97cc230dbb408524c0b7f6c89513f42af1b56c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 23 Dec 2024 18:10:55 +0100 Subject: [PATCH 4/5] chore: disable `kotlin.js.compiler` property --- gradle.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index cdd0da8..9d70e55 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,6 @@ kotlin.code.style=official kotlin.incremental.multiplatform=true kotlin.js.generate.executable.default=false -kotlin.js.compiler=both kotlin.native.ignoreDisabledTargets=true org.gradle.vfs.watch=true From ea8db73a1db08c133d18f0fdda21144ae3229834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Mon, 23 Dec 2024 18:15:11 +0100 Subject: [PATCH 5/5] chore: disable ktlint in `TestData` --- .../kotlinx/serialization/msgpack/TestData.kt | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt b/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt index 68b3379..11bd661 100644 --- a/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt +++ b/serialization-msgpack/src/commonTest/kotlin/com/ensarsarajcic/kotlinx/serialization/msgpack/TestData.kt @@ -1,3 +1,4 @@ +@file:Suppress("ktlint") package com.ensarsarajcic.kotlinx.serialization.msgpack import com.ensarsarajcic.kotlinx.serialization.msgpack.extensions.BaseMsgPackExtensionSerializer @@ -122,13 +123,8 @@ object TestData { arrayOf( "c409010203040506070809" to byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8, 9), "c400" to byteArrayOf(), - @Suppress("ktlint:standard:max-line-length") - "c4ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" - to - @Suppress("ktlint:standard:max-line-length") - byteArrayOf( - 116, 101, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, - ), + "c4ff746573747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474747474" to byteArrayOf(116, 101, 115, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116, 116 + ), ) val intArrayTestPairs = arrayOf(