Skip to content

Commit

Permalink
Merge pull request #122 from overpas/experiment-with-stability
Browse files Browse the repository at this point in the history
Make tree and nodes immutable, fix benchmark
  • Loading branch information
overpas authored Oct 20, 2024
2 parents ee4f853 + bddd4a2 commit 799fb07
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 99 deletions.
1 change: 1 addition & 0 deletions benchmark/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
54 changes: 54 additions & 0 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
alias(libs.plugins.android.test)
alias(libs.plugins.kotlin.android)
}

android {
namespace = "com.example.benchmark"
compileSdk = properties["android.compileSdk"].toString().toInt()

compileOptions {
sourceCompatibility = JavaVersion.toVersion(properties["jvm.version"].toString())
targetCompatibility = JavaVersion.toVersion(properties["jvm.version"].toString())
}

kotlinOptions {
jvmTarget = properties["jvm.version"].toString()
}

defaultConfig {
minSdk = properties["android.minSdk"].toString().toInt()
targetSdk = properties["android.targetSdk"].toString().toInt()

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunnerArguments["androidx.benchmark.suppressErrors"] = "EMULATOR"
}

buildTypes {
// This benchmark buildType is used for benchmarking, and should function like your
// release build (for example, with minification on). It"s signed with a debug key
// for easy local/CI testing.
create("benchmark") {
isDebuggable = true
// isMinifyEnabled = true
signingConfig = getByName("debug").signingConfig
matchingFallbacks += listOf("release")
}
}

targetProjectPath = ":sample:android"
experimentalProperties["android.experimental.self-instrumenting"] = true
}

dependencies {
implementation(libs.androidx.test.ext.junit)
implementation(libs.androidx.test.espresso.core)
implementation(libs.ui.automator)
implementation(libs.macrobenchmark.junit)
}

androidComponents {
beforeVariants(selector().all()) {
it.enable = it.buildType == "benchmark"
}
}
1 change: 1 addition & 0 deletions benchmark/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest />
103 changes: 103 additions & 0 deletions benchmark/src/main/java/com/example/benchmark/TreemapChartBenchmark.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.example.benchmark

import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.FrameTimingMetric
import androidx.benchmark.macro.MacrobenchmarkScope
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Until
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class TreemapChartBenchmark {

@get:Rule
val benchmarkRule = MacrobenchmarkRule()

@Test
fun showSimpleChart() = measureRepeated {
startActivityAndWait()

device.wait(Until.hasObject(By.text("4")), 1000)
device.wait(Until.hasObject(By.text("2")), 1000)
device.wait(Until.hasObject(By.text("1")), 1000)
}

@Test
fun showComplexChart() = benchmarkRule.measureRepeated(
packageName = "by.overpass.treemapchart.sample.android",
metrics = listOf(FrameTimingMetric()),
compilationMode = CompilationMode.DEFAULT,
startupMode = StartupMode.COLD,
iterations = 5,
) {
startActivityAndWait()

device.findObject(By.text("Show more complex chart"))
.click()

device.wait(
Until.hasObject(
By.text(
"""
|Cars
|12.11%
""".trimMargin(),
),
),
5000,
)
}

@Test
fun showComplexChartDetailPopup() = benchmarkRule.measureRepeated(
packageName = "by.overpass.treemapchart.sample.android",
metrics = listOf(FrameTimingMetric()),
compilationMode = CompilationMode.DEFAULT,
startupMode = StartupMode.COLD,
iterations = 5,
) {
startActivityAndWait()

device.findObject(By.text("Show more complex chart"))
.click()

device.wait(
Until.hasObject(
By.text(
"""
|Cars
|12.11%
""".trimMargin(),
),
),
5000,
)
device.findObject(
By.text(
"""
|Cars
|12.11%
""".trimMargin(),
),
).click()

device.wait(Until.hasObject(By.text("Exports value")), 5000)
device.wait(Until.hasObject(By.text("$88.6B")), 5000)
}

private fun measureRepeated(block: MacrobenchmarkScope.() -> Unit) {
benchmarkRule.measureRepeated(
packageName = "by.overpass.treemapchart.sample.android",
metrics = listOf(FrameTimingMetric()),
compilationMode = CompilationMode.DEFAULT,
startupMode = StartupMode.COLD,
iterations = 5,
measureBlock = block,
)
}
}
8 changes: 7 additions & 1 deletion sample/android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@ android {
isDebuggable = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
// create("benchmark") {
create("benchmark") {
initWith(buildTypes.getByName("release"))
signingConfig = signingConfigs.getByName("debug")
matchingFallbacks += listOf("release")
isDebuggable = false
}
// create("benchmark") {
// initWith(release)
// signingConfig = signingConfigs.getByName("debug")
// matchingFallbacks.add("release")
Expand Down
7 changes: 6 additions & 1 deletion sample/android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="by.overpass.treemapchart.sample.android">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:supportsRtl="true"
android:theme="@style/AppTheme">
<profileable android:shell="true" />
<profileable
android:shell="true"
tools:targetApi="29" />

<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Expand Down
8 changes: 8 additions & 0 deletions sample/shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,14 @@ dependencies {
detektPlugins(libs.compose.detekt.rules)
}

composeCompiler {
stabilityConfigurationFiles.add(project.layout.projectDirectory.file("stability.conf"))
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.fromTarget(properties["jvm.version"].toString())
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ package by.overpass.treemapchart.sample.shared.complex

import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.input.key.KeyEvent
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.window.Popup
import androidx.compose.ui.window.PopupProperties

@Suppress("LongParameterList")
@Composable
internal expect fun FocusablePopup(
internal fun FocusablePopup(
alignment: Alignment = Alignment.TopStart,
offset: IntOffset = IntOffset(0, 0),
onDismissRequest: (() -> Unit)? = null,
onPreviewKeyEvent: ((KeyEvent) -> Boolean) = { false },
onKeyEvent: ((KeyEvent) -> Boolean) = { false },
content: @Composable () -> Unit,
)
) {
Popup(
alignment = alignment,
offset = offset,
onDismissRequest = onDismissRequest,
properties = PopupProperties(
focusable = true,
),
content = content,
)
}

This file was deleted.

Empty file added sample/shared/stability.conf
Empty file.
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ include(":treemap-chart")
include(":treemap-chart-compose")
include(":sample:shared")
include(":sample:android")
//include(":sample:android:macrobenchmark")
include(":sample:desktop")
include(":sample:web")
include(":sample:web-wasm")
include(":benchmark")
8 changes: 8 additions & 0 deletions treemap-chart-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ dependencies {
debugImplementation(libs.androidx.compose.ui.test.manifest)
}

composeCompiler {
stabilityConfigurationFiles.add(project.layout.projectDirectory.file("stability.conf"))
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
compilerOptions {
jvmTarget = JvmTarget.fromTarget(properties["jvm.version"].toString())
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions treemap-chart/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ kotlin {
val commonMain by getting {
dependencies {
implementation(compose.runtime)
api(libs.kotlinx.collections.immutable)
}
}
val desktopMain by getting {
Expand Down Expand Up @@ -95,6 +96,14 @@ tasks.withType<KotlinCompile> {
}
}

composeCompiler {
stabilityConfigurationFiles.add(project.layout.projectDirectory.file("stability.conf"))
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
metricsDestination = layout.buildDirectory.dir("compose_compiler")
}
}

tasks.register("commonUnitTest") {
dependsOn("testDebugUnitTest", "desktopTest", "iosSimulatorArm64Test")
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package by.overpass.treemapchart.core.measure.squarified

import androidx.compose.runtime.Stable

/**
* An intermediary object to represent a [by.overpass.treemapchart.core.measure.TreemapNode]
*/
internal class TreemapElement(var area: Double) {
var left = 0.0
var top = 0.0
var width = 0.0
var height = 0.0
}
@Stable
internal data class TreemapElement(
var area: Double,
var left: Double = 0.0,
var top: Double = 0.0,
var width: Double = 0.0,
var height: Double = 0.0,
)
Loading

0 comments on commit 799fb07

Please sign in to comment.