make cloudstream very superfast boi, fast app startup and navigation (#965)

This commit is contained in:
IndusAryan 2024-03-23 03:26:05 +05:30 committed by GitHub
parent 86bc0b8345
commit faeb71da2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 48761 additions and 7 deletions

View file

@ -9,6 +9,7 @@ plugins {
id("com.google.devtools.ksp")
id("kotlin-android")
id("org.jetbrains.dokka")
id("androidx.baselineprofile")
}
val tmpFilePath = System.getProperty("user.home") + "/work/_temp/keystore/"
@ -232,6 +233,11 @@ dependencies {
implementation("androidx.work:work-runtime:2.9.0")
implementation("androidx.work:work-runtime-ktx:2.9.0")
implementation("com.github.Blatzar:NiceHttp:0.4.11") // HTTP Lib
// Baseline Profile and Automation
implementation("androidx.profileinstaller:profileinstaller:1.3.1")
implementation("androidx.test.uiautomator:uiautomator:2.3.0")
"baselineProfile"(project(":baselineprofile"))
}
tasks.register("androidSourcesJar", Jar::class) {

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

1
baselineProfile/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
/build

View file

@ -0,0 +1,52 @@
plugins {
id("com.android.test")
id("org.jetbrains.kotlin.android")
id("androidx.baselineprofile")
}
android {
namespace = "com.lagradost.cloudstream3.baselineprofile"
compileSdk = 34
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
defaultConfig {
minSdk = 28
targetSdk = 34
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
targetProjectPath = ":app"
flavorDimensions += listOf("state")
productFlavors {
create("stable") { dimension = "state" }
create("prerelease") { dimension = "state" }
}
}
// This is the configuration block for the Baseline Profile plugin.
// You can specify to run the generators on a managed devices or connected devices.
baselineProfile {
useConnectedDevices = true
}
repositories {
maven("https://jitpack.io")
}
dependencies {
implementation("androidx.test.ext:junit:1.1.5")
implementation("androidx.test.espresso:espresso-core:3.5.1")
implementation("androidx.test.uiautomator:uiautomator:2.2.0")
implementation("androidx.benchmark:benchmark-macro-junit4:1.2.2")
}

View file

@ -0,0 +1 @@
<manifest />

View file

@ -0,0 +1,73 @@
package com.lagradost.cloudstream3.baselineprofile
import androidx.benchmark.macro.junit4.BaselineProfileRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* This test class generates a basic startup baseline profile for the target package.
*
* We recommend you start with this but add important user flows to the profile to improve their performance.
* Refer to the [baseline profile documentation](https://d.android.com/topic/performance/baselineprofiles)
* for more information.
*
* You can run the generator with the "Generate Baseline Profile" run configuration in Android Studio or
* the equivalent `generateBaselineProfile` gradle task:
* ```
* ./gradlew :app:generateReleaseBaselineProfile
* ```
* The run configuration runs the Gradle task and applies filtering to run only the generators.
*
* Check [documentation](https://d.android.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args)
* for more information about available instrumentation arguments.
*
* After you run the generator, you can verify the improvements running the [StartupBenchmarks] benchmark.
*
* When using this class to generate a baseline profile, only API 33+ or rooted API 28+ are supported.
*
* The minimum required version of androidx.benchmark to generate a baseline profile is 1.2.0.
**/
@RunWith(AndroidJUnit4::class)
@LargeTest
class BaselineProfileGenerator {
@get:Rule
val rule = BaselineProfileRule()
@Test
fun generate() {
// This example works only with the variant with application id `com.lagradost.cloudstream3.prerelease`."
rule.collect(
packageName = "com.lagradost.cloudstream3.prerelease.debug",
/**
* KEEP PACKAGE NAME .DEBUG OTHERWISE ONE TEST (MACRO BENCHMARK) WILL FAIL AS IT NEEDS THE
* NAMESPACE BY WHICH APP IS BEING DEBUGGED || TESTED, PROFILES HAVE BEEN GENERATED FOR
* BOTH FLAVOURS STABLE AND PRE RELEASE MANUALLY
**/
// See: https://d.android.com/topic/performance/baselineprofiles/dex-layout-optimizations
includeInStartupProfile = true
) {
// This block defines the app's critical user journey. Here we are interested in
// optimizing for app startup. But you can also navigate and scroll through your most important UI.
// Start default activity for your app
pressHome()
startActivityAndWait()
// TODO Write more interactions to optimize more routes
// For example:
// 1. Wait until the content is asynchronously loaded
// 2. Scroll the feed content
// 3. Navigate to detail screen
// Check UiAutomator documentation for more information how to interact with the app.
// https://d.android.com/training/testing/other-components/ui-automator
}
}
}

View file

@ -0,0 +1,75 @@
package com.lagradost.cloudstream3.baselineprofile
import androidx.benchmark.macro.BaselineProfileMode
import androidx.benchmark.macro.CompilationMode
import androidx.benchmark.macro.StartupMode
import androidx.benchmark.macro.StartupTimingMetric
import androidx.benchmark.macro.junit4.MacrobenchmarkRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
/**
* This test class benchmarks the speed of app startup.
* Run this benchmark to verify how effective a Baseline Profile is.
* It does this by comparing [CompilationMode.None], which represents the app with no Baseline
* Profiles optimizations, and [CompilationMode.Partial], which uses Baseline Profiles.
*
* Run this benchmark to see startup measurements and captured system traces for verifying
* the effectiveness of your Baseline Profiles. You can run it directly from Android
* Studio as an instrumentation test, or run all benchmarks for a variant, for example benchmarkRelease,
* with this Gradle task:
* ```
* ./gradlew :baselineprofile:connectedBenchmarkReleaseAndroidTest
* ```
*
* You should run the benchmarks on a physical device, not an Android emulator, because the
* emulator doesn't represent real world performance and shares system resources with its host.
*
* For more information, see the [Macrobenchmark documentation](https://d.android.com/macrobenchmark#create-macrobenchmark)
* and the [instrumentation arguments documentation](https://d.android.com/topic/performance/benchmarking/macrobenchmark-instrumentation-args).
**/
@RunWith(AndroidJUnit4::class)
@LargeTest
class StartupBenchmarks {
@get:Rule
val rule = MacrobenchmarkRule()
@Test
fun startupCompilationNone() =
benchmark(CompilationMode.None())
@Test
fun startupCompilationBaselineProfiles() =
benchmark(CompilationMode.Partial(BaselineProfileMode.Require))
private fun benchmark(compilationMode: CompilationMode) {
// This example works only with the variant with application id `com.lagradost.cloudstream3.prerelease`."
rule.measureRepeated(
packageName = "com.lagradost.cloudstream3.prerelease.debug",
metrics = listOf(StartupTimingMetric()),
compilationMode = compilationMode,
startupMode = StartupMode.COLD,
iterations = 10,
setupBlock = {
pressHome()
},
measureBlock = {
startActivityAndWait()
// TODO Add interactions to wait for when your app is fully drawn.
// The app is fully drawn when Activity.reportFullyDrawn is called.
// For Jetpack Compose, you can use ReportDrawn, ReportDrawnWhen and ReportDrawnAfter
// from the AndroidX Activity library.
// Check the UiAutomator documentation for more information on how to
// interact with the app.
// https://d.android.com/training/testing/other-components/ui-automator
}
)
}
}

View file

@ -1,4 +1,3 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
@ -6,12 +5,9 @@ buildscript {
}
dependencies {
classpath("com.android.tools.build:gradle:8.2.1")
classpath("com.android.tools.build:gradle:8.2.2")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.22")
classpath("org.jetbrains.dokka:dokka-gradle-plugin:1.9.10")
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle.kts files
}
}
@ -23,7 +19,12 @@ allprojects {
}
plugins {
// these work only in this order, don't change.
id("com.google.devtools.ksp") version "1.9.22-1.0.16" apply false
id("com.android.test") version "8.2.2" apply false
id("org.jetbrains.kotlin.android") version "1.9.22" apply false
id("androidx.baselineprofile") version "1.2.2" apply false
id("com.android.application") version "8.2.2" apply false
}
tasks.register<Delete>("clean") {

View file

@ -1,6 +1,6 @@
#Fri Apr 30 17:11:15 CEST 2021
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

View file

@ -1,3 +1,12 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
rootProject.name = "CloudStream"
include(":app")
include(":app")
include(":baselineprofile")