From 3efd98df1a5edf951d9c5def83bf7f2b0f3f47c3 Mon Sep 17 00:00:00 2001 From: "Aleksei.Glushko" Date: Tue, 29 Aug 2023 10:52:33 +0000 Subject: [PATCH] [K/N] More work to do for weak-sweeper in weak ref benchmarks Merge-request: KT-MR-11899 Merged-by: Alexey Glushko --- .../performance/ring/src/main/kotlin/main.kt | 6 +++--- .../kotlin/org/jetbrains/ring/WeakRefBenchmark.kt | 6 ++++++ .../performance/swiftinterop/swiftSrc/main.swift | 15 +++++++++------ .../swiftinterop/swiftSrc/weakRefBenchmarks.swift | 7 ++++++- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/kotlin-native/performance/ring/src/main/kotlin/main.kt b/kotlin-native/performance/ring/src/main/kotlin/main.kt index 292e54c8593..562a9778c8c 100644 --- a/kotlin-native/performance/ring/src/main/kotlin/main.kt +++ b/kotlin-native/performance/ring/src/main/kotlin/main.kt @@ -236,9 +236,9 @@ class RingLauncher : Launcher() { "GenericArrayView.inlined" to BenchmarkEntryWithInit.create(::GenericArrayViewBenchmark, { inlined() }), "GenericArrayView.specialized" to BenchmarkEntryWithInit.create(::GenericArrayViewBenchmark, { specialized() }), "GenericArrayView.manual" to BenchmarkEntryWithInit.create(::GenericArrayViewBenchmark, { manual() }), - "WeakRefBenchmark.aliveReference" to BenchmarkEntryWithInit.create(::WeakRefBenchmark, { aliveReference() }), - "WeakRefBenchmark.deadReference" to BenchmarkEntryWithInit.create(::WeakRefBenchmark, { deadReference() }), - "WeakRefBenchmark.dyingReference" to BenchmarkEntryWithInit.create(::WeakRefBenchmark, { dyingReference() }), + "WeakRefBenchmark.aliveReference" to BenchmarkEntryWithInitAndValidation.create(::WeakRefBenchmark, { aliveReference() }, { clean() }), + "WeakRefBenchmark.deadReference" to BenchmarkEntryWithInitAndValidation.create(::WeakRefBenchmark, { deadReference() }, { clean() }), + "WeakRefBenchmark.dyingReference" to BenchmarkEntryWithInitAndValidation.create(::WeakRefBenchmark, { dyingReference() }, { clean() }), ) init { diff --git a/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/WeakRefBenchmark.kt b/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/WeakRefBenchmark.kt index 62f59a42462..4bd7f05601d 100644 --- a/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/WeakRefBenchmark.kt +++ b/kotlin-native/performance/ring/src/main/kotlin/org/jetbrains/ring/WeakRefBenchmark.kt @@ -51,6 +51,8 @@ private fun ReferenceWrapper.stress() = (1..REPEAT_COUNT).sumOf { @OptIn(kotlin.native.runtime.NativeRuntimeApi::class) open class WeakRefBenchmark { + private val weight = Array(BENCHMARK_SIZE) { ReferenceWrapper.create() } + private val aliveRef = ReferenceWrapper.create() private val deadRef = ReferenceWrapper.create().apply { dispose() @@ -76,4 +78,8 @@ open class WeakRefBenchmark { Blackhole.consume(ref.stress()) } + + fun clean() { + weight.forEach { it.dispose() } + } } diff --git a/kotlin-native/performance/swiftinterop/swiftSrc/main.swift b/kotlin-native/performance/swiftinterop/swiftSrc/main.swift index 6481cbf6c76..29c7f9e3fb3 100644 --- a/kotlin-native/performance/swiftinterop/swiftSrc/main.swift +++ b/kotlin-native/performance/swiftinterop/swiftSrc/main.swift @@ -38,23 +38,26 @@ swiftLauncher.addBase(name: "createMultigraphOfInt", benchmark: companion.create lambda: { ($0 as! SwiftInteropBenchmarks).simpleFunction() })) swiftLauncher.addBase( name: "WeakRefBenchmark.aliveReference", - benchmark: BenchmarkEntryWithInit.companion.create( + benchmark: BenchmarkEntryWithInitAndValidation.companion.create( ctor: { return WeakRefBenchmark() }, - lambda: { ($0 as! WeakRefBenchmark).aliveReference() } + benchmark: { ($0 as! WeakRefBenchmark).aliveReference() }, + validation: { ($0 as! WeakRefBenchmark).clean() } ) ) swiftLauncher.addBase( name: "WeakRefBenchmark.deadReference", - benchmark: BenchmarkEntryWithInit.companion.create( + benchmark: BenchmarkEntryWithInitAndValidation.companion.create( ctor: { return WeakRefBenchmark() }, - lambda: { ($0 as! WeakRefBenchmark).deadReference() } + benchmark: { ($0 as! WeakRefBenchmark).deadReference() }, + validation: { ($0 as! WeakRefBenchmark).clean() } ) ) swiftLauncher.addBase( name: "WeakRefBenchmark.dyingReference", - benchmark: BenchmarkEntryWithInit.companion.create( + benchmark: BenchmarkEntryWithInitAndValidation.companion.create( ctor: { return WeakRefBenchmark() }, - lambda: { ($0 as! WeakRefBenchmark).dyingReference() } + benchmark: { ($0 as! WeakRefBenchmark).dyingReference() }, + validation: { ($0 as! WeakRefBenchmark).clean() } ) ) diff --git a/kotlin-native/performance/swiftinterop/swiftSrc/weakRefBenchmarks.swift b/kotlin-native/performance/swiftinterop/swiftSrc/weakRefBenchmarks.swift index 3c5f73012bf..f6fe5a42361 100644 --- a/kotlin-native/performance/swiftinterop/swiftSrc/weakRefBenchmarks.swift +++ b/kotlin-native/performance/swiftinterop/swiftSrc/weakRefBenchmarks.swift @@ -7,7 +7,6 @@ import Foundation import benchmark private let REPEAT_COUNT = 10000 -private let REFERENCES_COUNT = 3 private class ReferenceWrapper { private weak var weakRef: KotlinData? @@ -49,6 +48,8 @@ private func deadReferenceWrapper() -> ReferenceWrapper { } class WeakRefBenchmark { + private let weight = (0..<10_000).map { _ in ReferenceWrapper() } + private let aliveRef = ReferenceWrapper() private let deadRef = deadReferenceWrapper() @@ -78,4 +79,8 @@ class WeakRefBenchmark { let counter = ref.stress() Blackhole.companion.consume(value: counter) } + + func clean() { + weight.forEach { $0.dispose() } + } }