Skip to content

Commit

Permalink
Add benchmarks for TypicalUserJourney, Enable baselineprofile generat…
Browse files Browse the repository at this point in the history
…or, and some metrics (#601)

* Add initial StartupBenchmarks

* Add startup profile gen + dex support for it

* Add current progress

* Fix benchmarks and TEMP remove DEX layout optimizations

* Update profiles using new UserJourney

* Add baseline gen config and general benchmark changes

* Update build.gradle fix warning DEBUGGABLE

* Enable compose compiler metrics

* Remove leftover comment

* Fix merge conflicts

* Fix formatting

* Fix merge issues

* Fix benchmarks

* Change baseline profile generator config

* Update util

* Fix benchmarks and update generated profiles

* Fix accidental changes

---------

Co-authored-by: Dessalines <[email protected]>
  • Loading branch information
MV-GH and dessalines authored Jun 20, 2023
1 parent 1056300 commit 9057eb0
Show file tree
Hide file tree
Showing 27 changed files with 46,295 additions and 17 deletions.
32 changes: 32 additions & 0 deletions .run/Generate Baseline Profile (show display).run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!--
This task runs the base profile generators with the display on
instead of headless but you will have to manually copy over the generated profiles
With something like this
adb -e pull "/storage/emulated/0/Android/media/com.jerboa.benchmarks/BaselineProfileGenerator_startup-baseline-prof-2022-03-08-13-37-55.txt
-->
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generate Baseline Profile (show display)" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":benchmarks:pixel6Api31BenchmarkAndroidTest" />
<option value="--rerun" />
<option value="--enable-display" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
</component>
24 changes: 24 additions & 0 deletions .run/Generate Baseline Profile.run.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="Generate Baseline Profile" type="GradleRunConfiguration" factoryName="Gradle">
<ExternalSystemSettings>
<option name="executionName" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="externalSystemIdString" value="GRADLE" />
<option name="scriptParameters" value="-Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile" />
<option name="taskDescriptions">
<list />
</option>
<option name="taskNames">
<list>
<option value=":app:generateReleaseBaselineProfile" />
</list>
</option>
<option name="vmOptions" />
</ExternalSystemSettings>
<ExternalSystemDebugServerProcess>true</ExternalSystemDebugServerProcess>
<ExternalSystemReattachDebugProcess>true</ExternalSystemReattachDebugProcess>
<DebugAllEnabled>false</DebugAllEnabled>
<ForceTestExec>false</ForceTestExec>
<method v="2" />
</configuration>
</component>
6 changes: 6 additions & 0 deletions app/benchmark-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Proguard rules for the `benchmark` build type.
#
# Obsfuscation must be disabled for the build variant that generates Baseline Profile, otherwise
# wrong symbols would be generated. The generated Baseline Profile will be properly applied when generated
# without obfuscation and your app is being obfuscated.
-dontobfuscate
14 changes: 13 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'com.google.devtools.ksp'
id 'androidx.baselineprofile'
}

android {
Expand Down Expand Up @@ -46,11 +47,19 @@ android {
signingConfig signingConfigs.release
}
}

debug {
applicationIdSuffix '.debug'
versionNameSuffix ' (DEBUG)'
}

generateProfiles { // use this variant to generate the profiles
minifyEnabled false // The startup profiles needs minification off
shrinkResources false
debuggable false
signingConfig signingConfigs.debug
proguardFiles 'benchmark-rules.pro' // The baseline profile generator needs obfuscation off
applicationIdSuffix = ".benchmark"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
Expand Down Expand Up @@ -134,4 +143,7 @@ dependencies {
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.4.3'
implementation "net.engawapg.lib:zoomable:1.4.3"
implementation 'androidx.browser:browser:1.5.0'

implementation 'androidx.profileinstaller:profileinstaller:1.3.1'
baselineProfile project(path: ':benchmarks')
}
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
android:supportsRtl="true"
android:theme="@style/Theme.Jerboa"
tools:targetApi="33">
<profileable android:shell="true"/>


<activity
android:name=".MainActivity"
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/com/jerboa/ui/components/common/AppBars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.tooling.preview.Preview
Expand Down Expand Up @@ -65,7 +66,7 @@ fun SimpleTopAppBar(
)
},
navigationIcon = {
IconButton(onClick = { navController.popBackStack() }) {
IconButton(onClick = { navController.popBackStack() }, modifier = Modifier.testTag("jerboa:back")) {
Icon(
Icons.Outlined.ArrowBack,
contentDescription = stringResource(R.string.topAppBar_back),
Expand Down Expand Up @@ -585,5 +586,5 @@ fun Modifier.simpleVerticalScrollbar(
fun LoadingBar(
padding: PaddingValues = PaddingValues(0.dp),
) {
LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(padding))
LinearProgressIndicator(modifier = Modifier.fillMaxWidth().padding(padding).testTag("jerboa:loading"))
}
9 changes: 7 additions & 2 deletions app/src/main/java/com/jerboa/ui/components/common/Dialogs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ import androidx.compose.runtime.livedata.observeAsState
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.tooling.preview.Preview
import com.jerboa.PostViewMode
import com.jerboa.R
Expand Down Expand Up @@ -313,6 +317,7 @@ fun ListingTypeOptionsDialogPreview() {
)
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun ShowChangelog(appSettingsViewModel: AppSettingsViewModel) {
val changelogViewed = appSettingsViewModel.appSettings.observeAsState().value?.viewedChangelog
Expand All @@ -325,7 +330,6 @@ fun ShowChangelog(appSettingsViewModel: AppSettingsViewModel) {

if (whatsChangedDialogOpen) {
val scrollState = rememberScrollState()

val markdown by appSettingsViewModel.changelog.collectAsState()
LaunchedEffect(appSettingsViewModel) {
appSettingsViewModel.updateChangelog()
Expand All @@ -350,7 +354,7 @@ fun ShowChangelog(appSettingsViewModel: AppSettingsViewModel) {
whatsChangedDialogOpen = false
appSettingsViewModel.markChangelogViewed()
},
modifier = Modifier.fillMaxWidth(),
modifier = Modifier.fillMaxWidth().testTag("jerboa:changelogbtn"),
) {
Text(stringResource(R.string.dialogs_done))
}
Expand All @@ -359,6 +363,7 @@ fun ShowChangelog(appSettingsViewModel: AppSettingsViewModel) {
whatsChangedDialogOpen = false
appSettingsViewModel.markChangelogViewed()
},
modifier = Modifier.semantics { testTagsAsResourceId = true },
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.jerboa.ui.theme.LARGE_PADDING
@Composable
fun IconAndTextDrawerItem(
text: String,
modifier: Modifier = Modifier,
icon: ImageVector? = null,
iconBadgeCount: Int? = null,
onClick: () -> Unit,
Expand All @@ -39,7 +40,7 @@ fun IconAndTextDrawerItem(
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween,
modifier = Modifier
modifier = modifier
.fillMaxWidth()
.clickable(onClick = onClick)
.background(
Expand Down
9 changes: 8 additions & 1 deletion app/src/main/java/com/jerboa/ui/components/home/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController
Expand Down Expand Up @@ -576,7 +580,7 @@ fun HomeHeader(
contentDescription = stringResource(R.string.selectSort),
)
}
IconButton(onClick = {
IconButton(modifier = Modifier.testTag("jerboa:options"), onClick = {
showMoreOptions = !showMoreOptions
}) {
Icon(
Expand Down Expand Up @@ -609,6 +613,7 @@ fun HomeHeaderPreview() {
)
}

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun HomeMoreDialog(
onDismissRequest: () -> Unit,
Expand All @@ -618,6 +623,7 @@ fun HomeMoreDialog(
) {
AlertDialog(
onDismissRequest = onDismissRequest,
modifier = Modifier.semantics { testTagsAsResourceId = true },
text = {
Column {
IconAndTextDrawerItem(
Expand All @@ -627,6 +633,7 @@ fun HomeMoreDialog(
onDismissRequest()
onClickRefresh()
},
modifier = Modifier.testTag("jerboa:refresh"),
)
IconAndTextDrawerItem(
text = stringResource(R.string.home_post_view_mode),
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/jerboa/ui/components/home/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jerboa.ui.components.home

import android.content.Context
import android.util.Log
import androidx.activity.compose.ReportDrawnWhen
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
Expand Down Expand Up @@ -32,10 +33,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.navigation.NavController
import com.jerboa.R
import com.jerboa.VoteType
Expand Down Expand Up @@ -64,7 +68,7 @@ import com.jerboa.ui.components.post.PostListings
import com.jerboa.ui.components.post.edit.PostEditViewModel
import kotlinx.coroutines.CoroutineScope

@OptIn(ExperimentalMaterial3Api::class)
@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun HomeActivity(
navController: NavController,
Expand Down Expand Up @@ -104,7 +108,8 @@ fun HomeActivity(
},
content = {
Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection)
.semantics { testTagsAsResourceId = true },
snackbarHost = { SnackbarHost(snackbarHostState) },
topBar = {
MainTopBar(
Expand Down Expand Up @@ -180,6 +185,7 @@ fun HomeActivity(
},
)
},
modifier = Modifier.semantics { testTagsAsResourceId = true },
)
}

Expand Down Expand Up @@ -213,6 +219,10 @@ fun MainPostListingsContent(

val loading = homeViewModel.postsRes == ApiState.Loading || homeViewModel.fetchingMore

ReportDrawnWhen {
!loading
}

val pullRefreshState = rememberPullRefreshState(
refreshing = loading,
onRefresh = {
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/java/com/jerboa/ui/components/post/PostActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.navigation.NavController
import com.jerboa.PostViewMode
import com.jerboa.R
Expand Down Expand Up @@ -67,6 +71,7 @@ import com.jerboa.ui.components.common.simpleVerticalScrollbar
import com.jerboa.ui.components.home.SiteViewModel
import com.jerboa.ui.components.post.edit.PostEditViewModel

@OptIn(ExperimentalComposeUiApi::class)
@Composable
fun CommentsHeaderTitle(
selectedSortType: CommentSortType,
Expand All @@ -85,7 +90,11 @@ fun CommentsHeaderTitle(
}
}

@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
@OptIn(
ExperimentalMaterialApi::class,
ExperimentalMaterial3Api::class,
ExperimentalComposeUiApi::class,
)
@Composable
fun PostActivity(
postViewModel: PostViewModel,
Expand Down Expand Up @@ -136,7 +145,8 @@ fun PostActivity(
}

Scaffold(
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection),
modifier = Modifier.nestedScroll(scrollBehavior.nestedScrollConnection)
.semantics { testTagsAsResourceId = true },
topBar = {
Column {
TopAppBar(
Expand All @@ -146,7 +156,10 @@ fun PostActivity(
)
},
navigationIcon = {
IconButton(onClick = { navController.popBackStack() }) {
IconButton(
modifier = Modifier.testTag("jerboa:back"),
onClick = { navController.popBackStack() },
) {
Icon(
Icons.Outlined.ArrowBack,
contentDescription = stringResource(R.string.topAppBar_back),
Expand Down Expand Up @@ -185,7 +198,8 @@ fun PostActivity(
state = listState,
modifier = Modifier
.padding(padding)
.simpleVerticalScrollbar(listState),
.simpleVerticalScrollbar(listState)
.testTag("jerboa:comments"),
) {
item(key = "${postView.post.id}_listing") {
PostListing(
Expand Down
Loading

0 comments on commit 9057eb0

Please sign in to comment.