From 9f4bf605592dc7c441274d47ec8e062efd2645f7 Mon Sep 17 00:00:00 2001 From: Clemente Date: Wed, 25 Oct 2023 15:31:53 +0200 Subject: [PATCH] Fix memory and multidex --- benchmarks/androidApp/build.gradle.kts | 1 + benchmarks/gradle.properties | 4 +- .../benchmark/OpenRealmTestsGenerated.kt | 78 +++++++++++++++++++ benchmarks/shared/build.gradle.kts | 1 + 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 benchmarks/jvmApp/src/jmh/kotlin/io/realm/kotlin/benchmark/OpenRealmTestsGenerated.kt diff --git a/benchmarks/androidApp/build.gradle.kts b/benchmarks/androidApp/build.gradle.kts index 68c7b0d5e6..6cca487b22 100644 --- a/benchmarks/androidApp/build.gradle.kts +++ b/benchmarks/androidApp/build.gradle.kts @@ -25,6 +25,7 @@ android { testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR,UNLOCKED" // Disable profiling. See https://developer.android.com/studio/profile/microbenchmark-profile testInstrumentationRunnerArguments["androidx.benchmark.profiling.mode"] = "None" + multiDexEnabled = true } testBuildType = "release" diff --git a/benchmarks/gradle.properties b/benchmarks/gradle.properties index 3211eb8167..48cd726e5f 100644 --- a/benchmarks/gradle.properties +++ b/benchmarks/gradle.properties @@ -1,6 +1,6 @@ #Gradle -org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M" - +org.gradle.jvmargs=-Xmx4096M +daemon.jvm.options=-Xmx4096M #Kotlin kotlin.code.style=official diff --git a/benchmarks/jvmApp/src/jmh/kotlin/io/realm/kotlin/benchmark/OpenRealmTestsGenerated.kt b/benchmarks/jvmApp/src/jmh/kotlin/io/realm/kotlin/benchmark/OpenRealmTestsGenerated.kt new file mode 100644 index 0000000000..cb6a933c61 --- /dev/null +++ b/benchmarks/jvmApp/src/jmh/kotlin/io/realm/kotlin/benchmark/OpenRealmTestsGenerated.kt @@ -0,0 +1,78 @@ +/* + * Copyright 2022 Realm Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.realm.kotlin.benchmark + +import io.realm.kotlin.Realm +import io.realm.kotlin.RealmConfiguration +import io.realm.kotlin.benchmarks.SCHEMAS +import io.realm.kotlin.benchmarks.SchemaSize +import io.realm.kotlin.types.RealmObject +import org.openjdk.jmh.annotations.Benchmark +import org.openjdk.jmh.annotations.BenchmarkMode +import org.openjdk.jmh.annotations.Fork +import org.openjdk.jmh.annotations.Level +import org.openjdk.jmh.annotations.Measurement +import org.openjdk.jmh.annotations.Mode +import org.openjdk.jmh.annotations.OutputTimeUnit +import org.openjdk.jmh.annotations.Param +import org.openjdk.jmh.annotations.Scope +import org.openjdk.jmh.annotations.Setup +import org.openjdk.jmh.annotations.State +import org.openjdk.jmh.annotations.TearDown +import org.openjdk.jmh.annotations.Warmup +import java.util.concurrent.TimeUnit +import kotlin.reflect.KClass + +/** + * Benchmarking how fast it is to open a Realm. + * Since this should never happen in hot path, we attempt to benchmark the cold start case. + * + * TODO Need to verify if `SingleShotTime` also include setup and teardown: http://mail.openjdk.java.net/pipermail/jmh-dev/2014-September/001364.html + */ +@Fork(1) +@Warmup(iterations = 0) +@Measurement(iterations = 100) +@BenchmarkMode(Mode.SingleShotTime) +@OutputTimeUnit(TimeUnit.MILLISECONDS) +@State(Scope.Benchmark) +open class OpenRealmTestsGenerated { + + @Param("SINGLE", "SMALL", "LARGE") // Must match enum names + var schemaSize: String = SchemaSize.SINGLE.name + var realm: Realm? = null + lateinit var config: RealmConfiguration + + @Setup(Level.Invocation) + fun setUp() { + val schema: Set> = SCHEMAS[schemaSize]!!.schemaObjects + config = RealmConfiguration.Builder(schema) + .directory("./build/benchmark-realms") + .build() + } + + @TearDown(Level.Invocation) + fun tearDown() { + realm?.let { + it.close() + Realm.deleteRealm(config) + } + } + + @Benchmark() + fun openRealm() { + realm = Realm.open(config) + } +} diff --git a/benchmarks/shared/build.gradle.kts b/benchmarks/shared/build.gradle.kts index c8429812d0..1aa32e6049 100644 --- a/benchmarks/shared/build.gradle.kts +++ b/benchmarks/shared/build.gradle.kts @@ -116,5 +116,6 @@ android { defaultConfig { minSdk = Versions.Android.minSdk targetSdk = Versions.Android.targetSdk + multiDexEnabled = true } } \ No newline at end of file