-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iOS target to multiplatform benchmarks (#5176)
Fixes [CMP-6807](https://youtrack.jetbrains.com/issue/CMP-6807/Add-iOS-target-to-our-own-benchmarks)
- Loading branch information
Showing
43 changed files
with
801 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
# Compose Multiplatform benchmarks | ||
|
||
## Run Desktop | ||
- `./gradlew :run` | ||
- `./gradlew :benchmarks:run` | ||
|
||
## Run native on iOS | ||
Open the project in Fleet or Android Studio with KMM plugin installed and | ||
choose `iosApp` run configuration. Make sure that you build the app in `Release` configuration. | ||
Alternatively you may open `iosApp/iosApp` project in XCode and run the app from there. | ||
|
||
## Run native on MacOS | ||
- `./gradlew runReleaseExecutableMacosArm64` (Works on Arm64 processors) | ||
- `./gradlew runReleaseExecutableMacosX64` (Works on Intel processors) | ||
- `./gradlew :benchmarks:runReleaseExecutableMacosArm64` (Works on Arm64 processors) | ||
- `./gradlew :benchmarks:runReleaseExecutableMacosX64` (Works on Intel processors) | ||
|
||
## Run in web browser: | ||
|
||
Please run your browser with manual GC enabled before running the benchmark, like for Google Chrome: | ||
|
||
`open -a Google\ Chrome --args --js-flags="--expose-gc"` | ||
|
||
- `./gradlew wasmJsBrowserProductionRun` (you can see the results printed on the page itself) | ||
- `./gradlew :benchmarks:wasmJsBrowserProductionRun` (you can see the results printed on the page itself) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import org.jetbrains.kotlin.gradle.ExperimentalWasmDsl | ||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.kotlin.plugin.compose") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenLocal() | ||
google() | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
} | ||
|
||
kotlin { | ||
jvm("desktop") | ||
|
||
listOf( | ||
iosX64(), | ||
iosArm64(), | ||
iosSimulatorArm64() | ||
).forEach { iosTarget -> | ||
iosTarget.binaries.framework { | ||
baseName = "benchmarks" | ||
isStatic = true | ||
} | ||
} | ||
|
||
listOf( | ||
macosX64(), | ||
macosArm64() | ||
).forEach { macosTarget -> | ||
macosTarget.binaries { | ||
executable { | ||
entryPoint = "main" | ||
} | ||
} | ||
} | ||
|
||
@OptIn(ExperimentalWasmDsl::class) | ||
wasmJs { | ||
binaries.executable() | ||
browser () | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(compose.ui) | ||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
implementation(compose.runtime) | ||
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) | ||
implementation(compose.components.resources) | ||
} | ||
} | ||
|
||
val desktopMain by getting { | ||
dependencies { | ||
implementation(compose.desktop.currentOs) | ||
runtimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.7.1") | ||
} | ||
} | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "Main_desktopKt" | ||
} | ||
} | ||
|
||
val runArguments: String? by project | ||
|
||
// Handle runArguments property | ||
gradle.taskGraph.whenReady { | ||
tasks.named<JavaExec>("run") { | ||
args(runArguments?.split(" ") ?: listOf<String>()) | ||
} | ||
tasks.forEach { t -> | ||
if ((t is Exec) && t.name.startsWith("runReleaseExecutableMacos")) { | ||
t.args(runArguments?.split(" ") ?: listOf<String>()) | ||
} | ||
} | ||
tasks.named<KotlinWebpack>("wasmJsBrowserProductionRun") { | ||
val args = runArguments?.split(" ") | ||
?.mapIndexed { index, arg -> "arg$index=$arg" } | ||
?.joinToString("&") ?: "" | ||
|
||
devServerProperty = devServerProperty.get().copy( | ||
open = "http://localhost:8080?$args" | ||
) | ||
} | ||
} |
74 changes: 74 additions & 0 deletions
74
benchmarks/multiplatform/benchmarks/src/appleMain/kotlin/GraphicsContext.apple.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import kotlinx.cinterop.ExperimentalForeignApi | ||
import kotlinx.cinterop.objcPtr | ||
import org.jetbrains.skia.BackendRenderTarget | ||
import org.jetbrains.skia.ColorSpace | ||
import org.jetbrains.skia.DirectContext | ||
import org.jetbrains.skia.PixelGeometry | ||
import org.jetbrains.skia.Surface | ||
import org.jetbrains.skia.SurfaceColorFormat | ||
import org.jetbrains.skia.SurfaceOrigin | ||
import org.jetbrains.skia.SurfaceProps | ||
import platform.Metal.MTLCreateSystemDefaultDevice | ||
import platform.Metal.MTLPixelFormatBGRA8Unorm | ||
import platform.Metal.MTLTextureDescriptor | ||
import platform.Metal.MTLTextureType2D | ||
import platform.Metal.MTLTextureUsageRenderTarget | ||
import platform.Metal.MTLTextureUsageShaderRead | ||
import platform.Metal.MTLTextureUsageShaderWrite | ||
import kotlin.coroutines.resume | ||
import kotlin.coroutines.suspendCoroutine | ||
|
||
@OptIn(ExperimentalForeignApi::class) | ||
fun graphicsContext() = object : GraphicsContext { | ||
private val device = MTLCreateSystemDefaultDevice() ?: throw IllegalStateException("Can't create MTLDevice") | ||
private val commandQueue = device.newCommandQueue() ?: throw IllegalStateException("Can't create MTLCommandQueue") | ||
private val directContext = DirectContext.makeMetal(device.objcPtr(), commandQueue.objcPtr()) | ||
private var cachedSurface: Surface? = null | ||
|
||
override fun surface(width: Int, height: Int): Surface { | ||
val oldSurface = cachedSurface | ||
|
||
if (oldSurface != null && oldSurface.width == width && oldSurface.height == height) { | ||
return oldSurface | ||
} | ||
|
||
val descriptor = MTLTextureDescriptor() | ||
descriptor.width = width.toULong() | ||
descriptor.height = height.toULong() | ||
descriptor.usage = MTLTextureUsageShaderRead or MTLTextureUsageShaderWrite or MTLTextureUsageRenderTarget | ||
descriptor.textureType = MTLTextureType2D | ||
descriptor.pixelFormat = MTLPixelFormatBGRA8Unorm | ||
descriptor.mipmapLevelCount = 1UL | ||
|
||
val texture = device.newTextureWithDescriptor(descriptor) ?: throw IllegalStateException("Can't create MTLTexture") | ||
|
||
val renderTarget = BackendRenderTarget.makeMetal(width, height, texture.objcPtr()) | ||
|
||
return Surface.makeFromBackendRenderTarget( | ||
directContext, | ||
renderTarget, | ||
SurfaceOrigin.TOP_LEFT, | ||
SurfaceColorFormat.BGRA_8888, | ||
ColorSpace.sRGB, | ||
SurfaceProps(pixelGeometry = PixelGeometry.UNKNOWN) | ||
).also { | ||
cachedSurface = it | ||
} ?: throw IllegalStateException("Can't create Surface") | ||
} | ||
|
||
override suspend fun awaitGPUCompletion() { | ||
val commandBuffer = commandQueue.commandBuffer() ?: return | ||
|
||
suspendCoroutine { continuation -> | ||
commandBuffer.addCompletedHandler { | ||
continuation.resume(Unit) | ||
} | ||
|
||
commandBuffer.commit() | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
benchmarks/multiplatform/benchmarks/src/iosMain/kotlin/main.ios.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
|
||
import kotlinx.coroutines.runBlocking | ||
|
||
fun main(args : List<String>) { | ||
Args.parseArgs(args.toTypedArray()) | ||
runBlocking { runBenchmarks(graphicsContext = graphicsContext()) } | ||
} |
10 changes: 10 additions & 0 deletions
10
benchmarks/multiplatform/benchmarks/src/macosMain/kotlin/main.macos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. | ||
* Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. | ||
*/ | ||
import kotlinx.coroutines.runBlocking | ||
|
||
fun main(args : Array<String>) { | ||
Args.parseArgs(args) | ||
runBlocking { runBenchmarks(graphicsContext = graphicsContext()) } | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,101 +1,15 @@ | ||
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack | ||
|
||
plugins { | ||
kotlin("multiplatform") | ||
id("org.jetbrains.kotlin.plugin.compose") | ||
id("org.jetbrains.compose") | ||
} | ||
|
||
version = "1.0-SNAPSHOT" | ||
|
||
repositories { | ||
mavenLocal() | ||
google() | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
} | ||
|
||
kotlin { | ||
jvm("desktop") | ||
macosX64 { | ||
binaries { | ||
executable { | ||
entryPoint = "main" | ||
} | ||
} | ||
} | ||
macosArm64 { | ||
binaries { | ||
executable { | ||
entryPoint = "main" | ||
} | ||
} | ||
} | ||
|
||
wasmJs { | ||
binaries.executable() | ||
browser () | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation(compose.ui) | ||
implementation(compose.foundation) | ||
implementation(compose.material) | ||
implementation(compose.runtime) | ||
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class) | ||
implementation(compose.components.resources) | ||
} | ||
} | ||
|
||
val desktopMain by getting { | ||
dependencies { | ||
implementation(compose.desktop.currentOs) | ||
runtimeOnly("org.jetbrains.kotlinx:kotlinx-coroutines-swing:1.7.1") | ||
} | ||
} | ||
|
||
val nativeMain by creating { | ||
dependsOn(commonMain) | ||
} | ||
val macosMain by creating { | ||
dependsOn(nativeMain) | ||
} | ||
val macosX64Main by getting { | ||
dependsOn(macosMain) | ||
} | ||
val macosArm64Main by getting { | ||
dependsOn(macosMain) | ||
} | ||
} | ||
} | ||
|
||
compose.desktop { | ||
application { | ||
mainClass = "Main_desktopKt" | ||
} | ||
} | ||
|
||
val runArguments: String? by project | ||
|
||
// Handle runArguments property | ||
gradle.taskGraph.whenReady { | ||
tasks.named<JavaExec>("run") { | ||
args(runArguments?.split(" ") ?: listOf<String>()) | ||
} | ||
tasks.forEach { t -> | ||
if ((t is Exec) && t.name.startsWith("runReleaseExecutableMacos")) { | ||
t.args(runArguments?.split(" ") ?: listOf<String>()) | ||
} | ||
} | ||
tasks.named<KotlinWebpack>("wasmJsBrowserProductionRun") { | ||
val args = runArguments?.split(" ") | ||
?.mapIndexed { index, arg -> "arg$index=$arg" } | ||
?.joinToString("&") ?: "" | ||
|
||
devServerProperty = devServerProperty.get().copy( | ||
open = "http://localhost:8080?$args" | ||
) | ||
// this is necessary to avoid the plugins to be loaded multiple times | ||
// in each subproject's classloader | ||
kotlin("multiplatform") apply false | ||
kotlin("plugin.compose") apply false | ||
id("org.jetbrains.compose") apply false | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
google() | ||
mavenCentral() | ||
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
benchmarks/multiplatform/iosApp/Configuration/Config.xcconfig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
TEAM_ID= | ||
BUNDLE_ID=org.jetbrains.benchmarks | ||
APP_NAME=ComposeBenchmarks |
Oops, something went wrong.