Skip to content

Commit

Permalink
Revive benchmarks (#5527)
Browse files Browse the repository at this point in the history
* unbreak running benchmarks

* fix SDK version

* wip

* fix compiling the microbenchmarks

* unbreak android compilation

* comments
  • Loading branch information
martinbonnin authored Jan 12, 2024
1 parent 49b8fef commit 2e7bef1
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
./gradlew --stop
- run: |
# Build the libs
./gradlew publishAllPublicationsToPluginTestRepository -x dokkatooGenerateModuleHtml
./gradlew publishAllPublicationsToPluginTestRepository
- run: |
# Build the benchmark apks
./gradlew -p benchmark assembleRelease assembleReleaseAndroidTest
Expand Down
5 changes: 5 additions & 0 deletions benchmark/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
android.useAndroidX=true

org.gradle.jvmargs=-Xmx8g

# See https://github.com/ben-manes/gradle-versions-plugin/issues/814#issuecomment-1752105377
systemProp.javax.xml.parsers.SAXParserFactory=com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl
systemProp.javax.xml.transform.TransformerFactory=com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl
systemProp.javax.xml.parsers.DocumentBuilderFactory=com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl
5 changes: 3 additions & 2 deletions benchmark/microbenchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ dependencies {
attributes {
attribute(relocated, true)
}
isTransitive = false
}
}
implementation(libs.moshi)
Expand All @@ -68,10 +69,10 @@ dependencies {

configure<com.android.build.gradle.LibraryExtension> {
namespace = "com.apollographql.apollo3.benchmark"
compileSdk = libs.versions.android.sdkversion.compile.get().toInt()
compileSdk = libs.versions.android.sdkversion.compilebenchmark.get().toInt()

defaultConfig {
minSdk = libs.versions.android.sdkversion.min.get().toInt()
minSdk = libs.versions.android.sdkversion.compilebenchmark.get().toInt()
testInstrumentationRunner = "androidx.benchmark.junit4.AndroidBenchmarkRunner"
}

Expand Down
21 changes: 21 additions & 0 deletions build-logic/src/main/kotlin/CompilerOptions.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import com.android.build.gradle.BaseExtension
import org.gradle.api.JavaVersion
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.gradle.api.tasks.compile.JavaCompile
Expand Down Expand Up @@ -70,6 +72,11 @@ val Project.kotlinExtensionOrNull: KotlinProjectExtension?
return (extensions.findByName("kotlin") as? KotlinProjectExtension)
}

val Project.androidExtensionOrNull: BaseExtension?
get() {
return (extensions.findByName("android") as? BaseExtension)
}

fun Project.configureJavaAndKotlinCompilers() {
kotlinExtensionOrNull?.forEachCompilerOptions {
configure()
Expand All @@ -80,6 +87,13 @@ fun Project.configureJavaAndKotlinCompilers() {
languageSettings.optIn("com.apollographql.apollo3.annotations.ApolloInternal")
}

/**
* We're using a toolchain to ensure build cache can be shared. Many tasks, including compileJava use the
* java version as input and using different JDKs will trash the cache.
* Note: It's unclear how the java version actually changes the behaviour of a task. We might be able to
* remove this in the future if compileJava and others remove it from their inputs.
* See https://issuetracker.google.com/issues/283097109
*/
@Suppress("UnstableApiUsage")
project.extensions.getByType(JavaPluginExtension::class.java).apply {
// Keep in sync with build-logic/build.gradle.kts
Expand All @@ -89,6 +103,13 @@ fun Project.configureJavaAndKotlinCompilers() {
// Ensure "org.gradle.jvm.version" is set to "8" in Gradle metadata of jvm-only modules.
options.release.set(8)
}
androidExtensionOrNull?.run {
compileOptions {
// Android somewhat does not honor `options.release.set(8)` above. Make sure to target
// Java 8 bytecode.
targetCompatibility = JavaVersion.VERSION_1_8
}
}

/**
* Required because of:
Expand Down
27 changes: 11 additions & 16 deletions build-logic/src/main/kotlin/Publishing.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import com.android.build.api.dsl.LibraryExtension
import com.android.build.gradle.BaseExtension
import dev.adamko.dokkatoo.DokkatooExtension
Expand Down Expand Up @@ -64,19 +63,6 @@ fun Project.configureDokkaCommon(): DokkatooExtension {
}

tasks.withType(DokkatooGenerateTask::class.java).configureEach {
/**
* Speed up development. When running the Gradle integration tests, we don't need KDoc to be generated
*/
onlyIf {
if (gradle.taskGraph.allTasks.any {
it.name == "publishAllPublicationsToPluginTestRepository" ||
it.name == "publishToMavenLocal"
}) {
return@onlyIf false
}
true
}

workerMaxHeapSize.set("8g")
}

Expand Down Expand Up @@ -114,7 +100,7 @@ fun Project.configureDokkaAggregate() {
)

val olderVersions = listOf<String>()
val kdocVersionTasks = olderVersions.map {version ->
val kdocVersionTasks = olderVersions.map { version ->
val versionString = version.replace(".", "_").replace("-", "_")
val configuration = configurations.create("apolloKdocVersion_$versionString") {
isCanBeResolved = true
Expand Down Expand Up @@ -287,7 +273,16 @@ private fun Project.configurePublishingInternal() {
}

create("default", MavenPublication::class.java) {
artifact(kdocWithoutOlder)
/**
* Speed up development. When running those manually, skip generating the kdoc.
* If you really need kdoc, use ./gradlew :apollo-kdoc:publishAllPublicationsToPluginTestRepository
*/
if (gradle.startParameter.taskNames.none {
it == "publishAllPublicationsToPluginTestRepository" ||
it == "publishToMavenLocal"
}) {
artifact(kdocWithoutOlder)
}

artifactId = project.name
}
Expand Down
5 changes: 3 additions & 2 deletions gradle/libraries.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[versions]
# The version we use by default in tests
android-plugin = "8.0.0"
# The version we use by default in tests and benchmarks
# Can be as high as IJ supports
android-plugin = "8.2.1"
# The version we compile against
android-plugin-min = "3.4.2"
# The latest version that has been tested to work
Expand Down

0 comments on commit 2e7bef1

Please sign in to comment.