Skip to content

Commit

Permalink
Implement optimization for Android with R8
Browse files Browse the repository at this point in the history
  • Loading branch information
whyoleg committed Aug 12, 2024
1 parent 4798a5d commit 795000a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion sweetspi-runtime/src/jvmMain/kotlin/InternalServiceLoader.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,17 @@ import java.util.*
@JvmField
@InternalSweetSpiApi
internal actual val internalServiceLoader: Lazy<InternalServiceLoader> = lazy {
InternalServiceLoader(ServiceLoader.load(InternalServiceModule::class.java).toList())
val modules = Iterable {
// ServiceLoader should use specific call convention to be optimized by R8 on Android:
// `ServiceLoader.load(X.class, X.class.getClassLoader()).iterator()`
// source:
// https://r8.googlesource.com/r8/+/refs/heads/main/src/main/java/com/android/tools/r8/ir/optimize/ServiceLoaderRewriter.java
ServiceLoader.load(
InternalServiceModule::class.java,
InternalServiceModule::class.java.classLoader
).iterator()
}.toList()
InternalServiceLoader(modules)
}

// IDEA shows an error because of a wrong visibility inspection
Expand Down

0 comments on commit 795000a

Please sign in to comment.