Skip to content

Commit

Permalink
Enable strong skipping by default
Browse files Browse the repository at this point in the history
^KT-69291
Relnote: Strong skipping is now enabled by default
  • Loading branch information
ShikaSD authored and Space Cloud committed Jun 25, 2024
1 parent cc39190 commit 192e556
Show file tree
Hide file tree
Showing 132 changed files with 718 additions and 498 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ abstract class ComposeCompilerGradlePluginExtension @Inject constructor(objectFa
* - [AndroidX strong skipping](https://github.com/androidx/androidx/blob/androidx-main/compose/compiler/design/strong-skipping.md)
*/
@Deprecated("Use the featureFlags option instead")
val enableStrongSkippingMode: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(false)
val enableStrongSkippingMode: Property<Boolean> = objectFactory.property(Boolean::class.java).convention(true)

/**
* Path to the stability configuration file.
Expand Down Expand Up @@ -174,8 +174,8 @@ abstract class ComposeCompilerGradlePluginExtension @Inject constructor(objectFa
// Add features that used to be added by deprecated options. No other features should be added this way.
enableIntrinsicRemember.zip(enableStrongSkippingMode) { intrinsicRemember, strongSkippingMode ->
setOfNotNull(
if (!intrinsicRemember) ComposeFeatureFlag.IntrinsicRemember.disable() else null,
if (strongSkippingMode) ComposeFeatureFlag.StrongSkipping else null
if (!intrinsicRemember) ComposeFeatureFlag.IntrinsicRemember.disabled() else null,
if (!strongSkippingMode) ComposeFeatureFlag.StrongSkipping.disabled() else null
)
}.zip(enableNonSkippingGroupOptimization) { features, nonSkippingGroupsOptimization ->
if (nonSkippingGroupsOptimization) features + ComposeFeatureFlag.OptimizeNonSkippingGroups else features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@ import java.io.Serializable
/**
* A feature flag is used to roll out features that will eventually become the default behavior of the Compose compiler plugin.
*
* A feature flag value that disables the feature can be created by calling [disable] on the feature flag.
* A feature flag value that disables the feature can be created by calling [disabled] on the feature flag.
*/
sealed interface ComposeFeatureFlag : Named, Serializable {
/**
* Return a feature flag that will disable this feature.
*/
fun disable(): ComposeFeatureFlag
fun disabled(): ComposeFeatureFlag

/**
* The enabled value of [feature]. These values are stored in a set they should have value identity.
*/
private class Enabled(val feature: Feature) : ComposeFeatureFlag, Serializable {
override fun disable() = Disabled(feature)
override fun disabled() = Disabled(feature)
override fun getName(): String = feature.name
override fun hashCode(): Int = feature.hashCode() * 17
override fun equals(other: Any?): Boolean = other is Enabled && other.feature == feature
Expand All @@ -34,7 +34,7 @@ sealed interface ComposeFeatureFlag : Named, Serializable {
* The disabled value of [feature]. These values are stored in a set they should have value identity.
*/
private class Disabled(val feature: Feature) : ComposeFeatureFlag, Serializable {
override fun disable(): ComposeFeatureFlag = this
override fun disabled(): ComposeFeatureFlag = this
override fun getName(): String = "Disabled ${feature.name}"
override fun hashCode(): Int = feature.hashCode() * 19
override fun equals(other: Any?): Boolean = other is Disabled && other.feature == feature
Expand Down Expand Up @@ -79,10 +79,10 @@ sealed interface ComposeFeatureFlag : Named, Serializable {
* For more information, see this link:
* - [Strong skipping](https://https://github.com/JetBrains/kotlin/blob/master/plugins/compose/design/strong-skipping.md)
*
* This feature is disabled by default. To enable, include this feature flag,
* This feature is enabled by default. To disable, provide this feature flag in a [disabled] state:
* ```
* composeOptions {
* featureFlags = setOf(ComposeFeatureFlag.StrongSkipping)
* featureFlags = setOf(ComposeFeatureFlag.StrongSkipping.disabled())
* }
* ```
*/
Expand All @@ -96,10 +96,10 @@ sealed interface ComposeFeatureFlag : Named, Serializable {
* invocations and replacing `.equals` comparison (for keys) with comparisons of the `$changed` meta parameter when possible. This
* results in fewer slots being used and fewer comparisons being done at runtime.
*
* This feature is on by default. It can be disabled by adding a disable flag by calling [disable] on this flag. To disable,
* This feature is enabled by default. To disable, provide this feature flag in a [disabled] state:
* ```
* composeOptions {
* featureFlags = setOf(ComposeFeatureFlag.IntrinsicRemember.disable())
* featureFlags = setOf(ComposeFeatureFlag.IntrinsicRemember.disabled())
* }
* ```
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ class ExtensionConfigurationTest {
@Test
fun disableIntrinsicRemember() {
testComposeFeatureFlags(listOf("-IntrinsicRemember")) { extension ->
extension.featureFlags.value(setOf(ComposeFeatureFlag.IntrinsicRemember.disable()))
extension.featureFlags.value(setOf(ComposeFeatureFlag.IntrinsicRemember.disabled()))
}
}

@Test
fun enableStrongSkipping() {
testComposeFeatureFlags(listOf("StrongSkipping")) { extension ->
extension.featureFlags.value(setOf(ComposeFeatureFlag.StrongSkipping))
fun disableStrongSkipping() {
testComposeFeatureFlags(listOf("-StrongSkipping")) { extension ->
extension.featureFlags.value(setOf(ComposeFeatureFlag.StrongSkipping.disabled()))
}
}

Expand All @@ -125,10 +125,10 @@ class ExtensionConfigurationTest {
}

@Test
fun enableStrongSkippingCompatibility() {
testComposeFeatureFlags(listOf("StrongSkipping")) { extension ->
fun disableStrongSkippingCompatibility() {
testComposeFeatureFlags(listOf("-StrongSkipping")) { extension ->
@Suppress("DEPRECATION")
extension.enableStrongSkippingMode.value(true)
extension.enableStrongSkippingMode.value(false)
}
}

Expand All @@ -142,11 +142,11 @@ class ExtensionConfigurationTest {

@Test
fun enableMultipleFlags() {
testComposeFeatureFlags(listOf("OptimizeNonSkippingGroups", "StrongSkipping", "-IntrinsicRemember")) { extension ->
testComposeFeatureFlags(listOf("OptimizeNonSkippingGroups", "-StrongSkipping", "-IntrinsicRemember")) { extension ->
extension.featureFlags.set(
setOf(
ComposeFeatureFlag.StrongSkipping,
ComposeFeatureFlag.IntrinsicRemember.disable(),
ComposeFeatureFlag.StrongSkipping.disabled(),
ComposeFeatureFlag.IntrinsicRemember.disabled(),
ComposeFeatureFlag.OptimizeNonSkippingGroups
)
)
Expand All @@ -156,13 +156,23 @@ class ExtensionConfigurationTest {
@Test
fun enableMultipleFlagsCompatibility() {
@Suppress("DEPRECATION")
testComposeFeatureFlags(listOf("OptimizeNonSkippingGroups", "StrongSkipping", "-IntrinsicRemember")) { extension ->
extension.enableStrongSkippingMode.value(true)
testComposeFeatureFlags(listOf("OptimizeNonSkippingGroups", "-StrongSkipping", "-IntrinsicRemember")) { extension ->
extension.enableStrongSkippingMode.value(false)
extension.enableNonSkippingGroupOptimization.value(true)
extension.enableIntrinsicRemember.value(false)
}
}

@Test
fun enableMultipleFlagsCompatibilityDefaults() {
@Suppress("DEPRECATION")
testComposeFeatureFlags(emptyList()) { extension ->
extension.enableStrongSkippingMode.value(true)
extension.enableNonSkippingGroupOptimization.value(false)
extension.enableIntrinsicRemember.value(true)
}
}

private fun testComposeFeatureFlags(flags: List<String>, configure: (ComposeCompilerGradlePluginExtension) -> Unit) {
testComposeOptions({ extension, _ -> configure(extension) }) { options, _ ->
for (flag in flags) options.assertFeature(flag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fun Test(%context_receiver_0: Foo, a: String, b: Function3<String, Composer, Int
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)<b("yay...>:Test.kt")
val %dirty = %changed
if (%changed and 0b001110000000 == 0) {
if (%changed and 0b000110000000 == 0) {
%dirty = %dirty or if (%composer.changedInstance(b)) 0b000100000000 else 0b10000000
}
if (%dirty and 0b001010000001 != 0b10000000 || !%composer.skipping) {
if (%dirty and 0b10000001 != 0b10000000 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fun Test(%context_receiver_0: Foo, a: String, b: Function3<String, Composer, Int
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)<b("yay...>:Test.kt")
val %dirty = %changed
if (%changed and 0b001110000000 == 0) {
if (%changed and 0b000110000000 == 0) {
%dirty = %dirty or if (%composer.changedInstance(b)) 0b000100000000 else 0b10000000
}
if (%dirty and 0b001010000001 != 0b10000000 || !%composer.skipping) {
if (%dirty and 0b10000001 != 0b10000000 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ fun Test(%context_receiver_0: Foo, a: String?, b: Int, %composer: Composer?, %ch
val %dirty = %changed
if (%default and 0b0001 != 0) {
%dirty = %dirty or 0b0110
} else if (%changed and 0b1110 == 0) {
} else if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(%context_receiver_0)) 0b0100 else 0b0010
}
if (%default and 0b0010 != 0) {
%dirty = %dirty or 0b00110000
} else if (%changed and 0b01110000 == 0) {
} else if (%changed and 0b00110000 == 0) {
%dirty = %dirty or if (%composer.changed(a)) 0b00100000 else 0b00010000
}
if (%default and 0b0100 != 0) {
%dirty = %dirty or 0b000110000000
} else if (%changed and 0b001110000000 == 0) {
} else if (%changed and 0b000110000000 == 0) {
%dirty = %dirty or if (%composer.changed(b)) 0b000100000000 else 0b10000000
}
if (%dirty and 0b001011011011 != 0b10010010 || !%composer.skipping) {
if (%dirty and 0b10010011 != 0b10010010 || !%composer.skipping) {
if (%default and 0b0010 != 0) {
a = "A"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ fun Test(%context_receiver_0: Foo, a: String?, b: Int, %composer: Composer?, %ch
val %dirty = %changed
if (%default and 0b0001 != 0) {
%dirty = %dirty or 0b0110
} else if (%changed and 0b1110 == 0) {
} else if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(%context_receiver_0)) 0b0100 else 0b0010
}
if (%default and 0b0010 != 0) {
%dirty = %dirty or 0b00110000
} else if (%changed and 0b01110000 == 0) {
} else if (%changed and 0b00110000 == 0) {
%dirty = %dirty or if (%composer.changed(a)) 0b00100000 else 0b00010000
}
if (%default and 0b0100 != 0) {
%dirty = %dirty or 0b000110000000
} else if (%changed and 0b001110000000 == 0) {
} else if (%changed and 0b000110000000 == 0) {
%dirty = %dirty or if (%composer.changed(b)) 0b000100000000 else 0b10000000
}
if (%dirty and 0b001011011011 != 0b10010010 || !%composer.skipping) {
if (%dirty and 0b10010011 != 0b10010010 || !%composer.skipping) {
if (%default and 0b0010 != 0) {
a = "A"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fun Test(foo: Foo, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)*<A()>:Test.kt")
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(foo)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fun Test(foo: Foo, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)*<A()>:Test.kt")
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(foo)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fun Test(foo: Foo, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)*<A(2)>:Test.kt")
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(foo)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ fun Test(foo: Foo, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)*<A(2)>:Test.kt")
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(foo)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fun Test(foo: Foo, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)*<A()>:Test.kt")
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(foo)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fun Test(foo: Foo, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
sourceInformation(%composer, "C(Test)*<A()>:Test.kt")
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(foo)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
if (isTraceInProgress()) {
traceEventStart(<>, %dirty, -1, <>)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ fun Label(test: Boolean) {
fun Label(test: Boolean, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(test)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
OuterComposableFunction(rememberComposableLambda(<>, true, { %composer: Composer?, %changed: Int ->
val tmp0_marker = %composer.currentMarker
if (%changed and 0b1011 != 0b0010 || !%composer.skipping) {
if (%changed and 0b0011 != 0b0010 || !%composer.skipping) {
Column(null, null, null, { %composer: Composer?, %changed: Int ->
%composer.startReplaceGroup(<>)
if (test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ fun Label(test: Boolean) {
fun Label(test: Boolean, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(test)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
OuterComposableFunction(rememberComposableLambda(<>, true, { %composer: Composer?, %changed: Int ->
val tmp0_marker = %composer.currentMarker
if (%changed and 0b1011 != 0b0010 || !%composer.skipping) {
if (%changed and 0b0011 != 0b0010 || !%composer.skipping) {
Column(null, null, null, { %composer: Composer?, %changed: Int ->
%composer.startReplaceGroup(<>)
if (test) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun Test(%composer: Composer?, %changed: Int) {
}
internal object ComposableSingletons%TestKt {
val lambda-1: Function2<Composer, Int, Unit> = composableLambdaInstance(<>, false) { %composer: Composer?, %changed: Int ->
if (%changed and 0b1011 != 0b0010 || !%composer.skipping) {
if (%changed and 0b0011 != 0b0010 || !%composer.skipping) {
A(%composer, 0)
} else {
%composer.skipToGroupEnd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fun Test(%composer: Composer?, %changed: Int) {
}
internal object ComposableSingletons%TestKt {
val lambda-1: Function2<Composer, Int, Unit> = composableLambdaInstance(<>, false) { %composer: Composer?, %changed: Int ->
if (%changed and 0b1011 != 0b0010 || !%composer.skipping) {
if (%changed and 0b0011 != 0b0010 || !%composer.skipping) {
A(%composer, 0)
} else {
%composer.skipToGroupEnd()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ fun Test(count: Int) {
fun Test(count: Int, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(count)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
Row(null, null, null, { %composer: Composer?, %changed: Int ->
%composer.startReplaceGroup(<>)
repeat(count) { it: Int ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ fun Test(count: Int) {
fun Test(count: Int, %composer: Composer?, %changed: Int) {
%composer = %composer.startRestartGroup(<>)
val %dirty = %changed
if (%changed and 0b1110 == 0) {
if (%changed and 0b0110 == 0) {
%dirty = %dirty or if (%composer.changed(count)) 0b0100 else 0b0010
}
if (%dirty and 0b1011 != 0b0010 || !%composer.skipping) {
if (%dirty and 0b0011 != 0b0010 || !%composer.skipping) {
Row(null, null, null, { %composer: Composer?, %changed: Int ->
%composer.startReplaceGroup(<>)
repeat(count) { it: Int ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val layoutLambda = @Composable { _: Int ->
val layoutLambda: Function3<Int, Composer, Int, Unit> = ComposableSingletons%TestKt.lambda-1
internal object ComposableSingletons%TestKt {
val lambda-1: Function3<Int, Composer, Int, Unit> = composableLambdaInstance(<>, false) { <unused var>: Int, %composer: Composer?, %changed: Int ->
if (%changed and 0b01010001 != 0b00010000 || !%composer.skipping) {
if (%changed and 0b00010001 != 0b00010000 || !%composer.skipping) {
Layout(%composer, 0)
} else {
%composer.skipToGroupEnd()
Expand Down
Loading

0 comments on commit 192e556

Please sign in to comment.