Skip to content

Commit 75a3295

Browse files
committed
Merge branch 'main' into mlykotom/tz-perf-improvement
Change-Id: I8730afc0cc3786784ea47276873fdf48dd82081c # Conflicts: # app/dependencies/prodReleaseRuntimeClasspath.txt # build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt
2 parents 9499293 + dba36d6 commit 75a3295

File tree

13 files changed

+108
-100
lines changed

13 files changed

+108
-100
lines changed

.github/workflows/Build.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,9 @@ jobs:
109109
- name: Build all build type and flavor permutations
110110
run: ./gradlew :app:assemble :benchmarks:assemble
111111
-x pixel6Api33ProdNonMinifiedReleaseAndroidTest
112-
-x pixel6Api33ProdNonMinifiedBenchmarkAndroidTest
113112
-x pixel6Api33DemoNonMinifiedReleaseAndroidTest
114-
-x pixel6Api33DemoNonMinifiedBenchmarkAndroidTest
115113
-x collectDemoNonMinifiedReleaseBaselineProfile
116-
-x collectDemoNonMinifiedBenchmarkBaselineProfile
117114
-x collectProdNonMinifiedReleaseBaselineProfile
118-
-x collectProdNonMinifiedBenchmarkBaselineProfile
119115

120116
- name: Upload build outputs (APKs)
121117
uses: actions/upload-artifact@v4
@@ -151,6 +147,17 @@ jobs:
151147
api-level: [26, 30]
152148

153149
steps:
150+
- name: Delete unnecessary tools 🔧
151+
uses: jlumbroso/[email protected]
152+
with:
153+
android: false # Don't remove Android tools
154+
tool-cache: true # Remove image tool cache - rm -rf "$AGENT_TOOLSDIRECTORY"
155+
dotnet: true # rm -rf /usr/share/dotnet
156+
haskell: true # rm -rf /opt/ghc...
157+
swap-storage: true # rm -f /mnt/swapfile (4GiB)
158+
docker-images: false # Takes 16s, enable if needed in the future
159+
large-packages: false # includes google-cloud-sdk and it's slow
160+
154161
- name: Enable KVM group perms
155162
run: |
156163
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules

app/build.gradle.kts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,6 @@ android {
5757
// Ensure Baseline Profile is fresh for release builds.
5858
baselineProfile.automaticGenerationDuringBuild = true
5959
}
60-
create("benchmark") {
61-
// Enable all the optimizations from release build through initWith(release).
62-
initWith(release)
63-
matchingFallbacks.add("release")
64-
// Debug key signing is available to everyone.
65-
signingConfig = signingConfigs.getByName("debug")
66-
// Only use benchmark proguard rules
67-
proguardFiles("benchmark-rules.pro")
68-
isMinifyEnabled = true
69-
applicationIdSuffix = NiaBuildType.BENCHMARK.applicationIdSuffix
70-
}
7160
}
7261

7362
packaging {

app/dependencies/prodReleaseRuntimeClasspath.txt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,20 @@ androidx.hilt:hilt-navigation:1.0.0
7272
androidx.hilt:hilt-work:1.1.0
7373
androidx.interpolator:interpolator:1.0.0
7474
androidx.legacy:legacy-support-core-utils:1.0.0
75-
androidx.lifecycle:lifecycle-common-java8:2.6.2
76-
androidx.lifecycle:lifecycle-common:2.6.2
77-
androidx.lifecycle:lifecycle-livedata-core:2.6.2
78-
androidx.lifecycle:lifecycle-livedata:2.6.2
79-
androidx.lifecycle:lifecycle-process:2.6.2
80-
androidx.lifecycle:lifecycle-runtime-compose:2.6.2
81-
androidx.lifecycle:lifecycle-runtime-ktx:2.6.2
82-
androidx.lifecycle:lifecycle-runtime:2.6.2
83-
androidx.lifecycle:lifecycle-service:2.6.2
84-
androidx.lifecycle:lifecycle-viewmodel-compose:2.6.2
85-
androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.2
86-
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.6.2
87-
androidx.lifecycle:lifecycle-viewmodel:2.6.2
75+
androidx.lifecycle:lifecycle-common-java8:2.7.0
76+
androidx.lifecycle:lifecycle-common:2.7.0
77+
androidx.lifecycle:lifecycle-livedata-core-ktx:2.7.0
78+
androidx.lifecycle:lifecycle-livedata-core:2.7.0
79+
androidx.lifecycle:lifecycle-livedata:2.7.0
80+
androidx.lifecycle:lifecycle-process:2.7.0
81+
androidx.lifecycle:lifecycle-runtime-compose:2.7.0
82+
androidx.lifecycle:lifecycle-runtime-ktx:2.7.0
83+
androidx.lifecycle:lifecycle-runtime:2.7.0
84+
androidx.lifecycle:lifecycle-service:2.7.0
85+
androidx.lifecycle:lifecycle-viewmodel-compose:2.7.0
86+
androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0
87+
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.7.0
88+
androidx.lifecycle:lifecycle-viewmodel:2.7.0
8889
androidx.loader:loader:1.0.0
8990
androidx.localbroadcastmanager:localbroadcastmanager:1.0.0
9091
androidx.metrics:metrics-performance:1.0.0-alpha04
@@ -170,8 +171,8 @@ com.google.guava:failureaccess:1.0.1
170171
com.google.guava:guava:31.1-android
171172
com.google.guava:listenablefuture:9999.0-empty-to-avoid-conflict-with-guava
172173
com.google.j2objc:j2objc-annotations:1.3
173-
com.google.protobuf:protobuf-javalite:3.24.4
174-
com.google.protobuf:protobuf-kotlin-lite:3.24.4
174+
com.google.protobuf:protobuf-javalite:3.25.2
175+
com.google.protobuf:protobuf-kotlin-lite:3.25.2
175176
com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0
176177
com.squareup.okhttp3:logging-interceptor:4.12.0
177178
com.squareup.okhttp3:okhttp:4.12.0

app/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaApplication.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,14 @@ import com.google.samples.apps.nowinandroid.sync.initializers.Sync
2323
import com.google.samples.apps.nowinandroid.util.ProfileVerifierLogger
2424
import dagger.hilt.android.HiltAndroidApp
2525
import javax.inject.Inject
26-
import javax.inject.Provider
2726

2827
/**
2928
* [Application] class for NiA
3029
*/
3130
@HiltAndroidApp
3231
class NiaApplication : Application(), ImageLoaderFactory {
3332
@Inject
34-
lateinit var imageLoader: Provider<ImageLoader>
33+
lateinit var imageLoader: dagger.Lazy<ImageLoader>
3534

3635
@Inject
3736
lateinit var profileVerifierLogger: ProfileVerifierLogger

benchmarks/build.gradle.kts

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import com.google.samples.apps.nowinandroid.NiaBuildType
1716
import com.google.samples.apps.nowinandroid.configureFlavors
1817

1918
plugins {
@@ -35,23 +34,6 @@ android {
3534
buildConfig = true
3635
}
3736

38-
buildTypes {
39-
// This benchmark buildType is used for benchmarking, and should function like your
40-
// release build (for example, with minification on). It's signed with a debug key
41-
// for easy local/CI testing.
42-
create("benchmark") {
43-
// Keep the build type debuggable so we can attach a debugger if needed.
44-
isDebuggable = true
45-
signingConfig = signingConfigs.getByName("debug")
46-
matchingFallbacks.add("release")
47-
buildConfigField(
48-
"String",
49-
"APP_BUILD_TYPE_SUFFIX",
50-
"\"${NiaBuildType.BENCHMARK.applicationIdSuffix ?: ""}\""
51-
)
52-
}
53-
}
54-
5537
// Use the same flavor dimensions as the application to allow generating Baseline Profiles on prod,
5638
// which is more close to what will be shipped to users (no fake data), but has ability to run the
5739
// benchmarks on demo, so we benchmark on stable data.

benchmarks/src/main/kotlin/com/google/samples/apps/nowinandroid/Utils.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import java.io.ByteArrayOutputStream
3030
val PACKAGE_NAME = buildString {
3131
append("com.google.samples.apps.nowinandroid")
3232
append(BuildConfig.APP_FLAVOR_SUFFIX)
33-
append(BuildConfig.APP_BUILD_TYPE_SUFFIX)
3433
}
3534

3635
fun UiDevice.flingElementDownUp(element: UiObject2) {

build-logic/convention/src/main/kotlin/AndroidFeatureConventionPlugin.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ class AndroidFeatureConventionPlugin : Plugin<Project> {
4444
add("implementation", libs.findLibrary("androidx.hilt.navigation.compose").get())
4545
add("implementation", libs.findLibrary("androidx.lifecycle.runtimeCompose").get())
4646
add("implementation", libs.findLibrary("androidx.lifecycle.viewModelCompose").get())
47-
4847
add("implementation", libs.findLibrary("androidx.tracing.ktx").get())
48+
49+
add("androidTestImplementation", libs.findLibrary("androidx.lifecycle.runtimeTesting").get())
4950
}
5051
}
5152
}

build-logic/convention/src/main/kotlin/com/google/samples/apps/nowinandroid/NiaBuildType.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ package com.google.samples.apps.nowinandroid
2222
enum class NiaBuildType(val applicationIdSuffix: String? = null) {
2323
DEBUG(".debug"),
2424
RELEASE,
25-
BENCHMARK(".benchmark")
2625
}

core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.samples.apps.nowinandroid.core.network.di
1818

1919
import android.content.Context
20+
import androidx.tracing.trace
2021
import coil.ImageLoader
2122
import coil.decode.SvgDecoder
2223
import coil.util.DebugLogger
@@ -51,16 +52,18 @@ internal object NetworkModule {
5152

5253
@Provides
5354
@Singleton
54-
fun okHttpCallFactory(): Call.Factory = OkHttpClient.Builder()
55-
.addInterceptor(
56-
HttpLoggingInterceptor()
57-
.apply {
58-
if (BuildConfig.DEBUG) {
59-
setLevel(HttpLoggingInterceptor.Level.BODY)
60-
}
61-
},
62-
)
63-
.build()
55+
fun okHttpCallFactory(): Call.Factory = trace("NiaOkHttpClient") {
56+
OkHttpClient.Builder()
57+
.addInterceptor(
58+
HttpLoggingInterceptor()
59+
.apply {
60+
if (BuildConfig.DEBUG) {
61+
setLevel(HttpLoggingInterceptor.Level.BODY)
62+
}
63+
},
64+
)
65+
.build()
66+
}
6467

6568
/**
6669
* Since we're displaying SVGs in the app, Coil needs an ImageLoader which supports this
@@ -72,20 +75,21 @@ internal object NetworkModule {
7275
@Provides
7376
@Singleton
7477
fun imageLoader(
75-
okHttpCallFactory: Call.Factory,
78+
// We specifically request dagger.Lazy here, so that it's not instantiated from Dagger.
79+
okHttpCallFactory: dagger.Lazy<Call.Factory>,
7680
@ApplicationContext application: Context,
77-
): ImageLoader = ImageLoader.Builder(application)
78-
.callFactory(okHttpCallFactory)
79-
.components {
80-
add(SvgDecoder.Factory())
81-
}
82-
// Assume most content images are versioned urls
83-
// but some problematic images are fetching each time
84-
.respectCacheHeaders(false)
85-
.apply {
86-
if (BuildConfig.DEBUG) {
87-
logger(DebugLogger())
81+
): ImageLoader = trace("NiaImageLoader") {
82+
ImageLoader.Builder(application)
83+
.callFactory { okHttpCallFactory.get() }
84+
.components { add(SvgDecoder.Factory()) }
85+
// Assume most content images are versioned urls
86+
// but some problematic images are fetching each time
87+
.respectCacheHeaders(false)
88+
.apply {
89+
if (BuildConfig.DEBUG) {
90+
logger(DebugLogger())
91+
}
8892
}
89-
}
90-
.build()
93+
.build()
94+
}
9195
}

core/network/src/main/kotlin/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiaNetwork.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.google.samples.apps.nowinandroid.core.network.retrofit
1818

19+
import androidx.tracing.trace
1920
import com.google.samples.apps.nowinandroid.core.network.BuildConfig
2021
import com.google.samples.apps.nowinandroid.core.network.NiaNetworkDataSource
2122
import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList
@@ -73,17 +74,21 @@ private data class NetworkResponse<T>(
7374
@Singleton
7475
internal class RetrofitNiaNetwork @Inject constructor(
7576
networkJson: Json,
76-
okhttpCallFactory: Call.Factory,
77+
okhttpCallFactory: dagger.Lazy<Call.Factory>,
7778
) : NiaNetworkDataSource {
7879

79-
private val networkApi = Retrofit.Builder()
80-
.baseUrl(NIA_BASE_URL)
81-
.callFactory(okhttpCallFactory)
82-
.addConverterFactory(
83-
networkJson.asConverterFactory("application/json".toMediaType()),
84-
)
85-
.build()
86-
.create(RetrofitNiaNetworkApi::class.java)
80+
private val networkApi = trace("RetrofitNiaNetwork") {
81+
Retrofit.Builder()
82+
.baseUrl(NIA_BASE_URL)
83+
// We use callFactory lambda here with dagger.Lazy<Call.Factory>
84+
// to prevent initializing OkHttp on the main thread.
85+
.callFactory { okhttpCallFactory.get().newCall(it) }
86+
.addConverterFactory(
87+
networkJson.asConverterFactory("application/json".toMediaType()),
88+
)
89+
.build()
90+
.create(RetrofitNiaNetworkApi::class.java)
91+
}
8792

8893
override suspend fun getTopics(ids: List<String>?): List<NetworkTopic> =
8994
networkApi.getTopics(ids = ids).data

0 commit comments

Comments
 (0)