We hit an issue with a Jacoco task where it wasn't able to initialize the XRootCodegen file anymore as our codebase had reached the limit of components it was able to support. This was specifically happening if you used Jacoco as it tries to do a few things internally that initializes each class that's going to be processed for code coverage.
Error while instrumenting com/airbnb/android/feat/aggregator/showkase/MyShowkaseRootCodegen.class with JaCoCo 0.8.8.202204050719/5dcf34a.
> Method too large: com/airbnb/android/feat/aggregator/showkase/MyShowkaseRootCodegen.<init> ()V
In this PR, I've implemented a couple changes:
Each ShowkaseMetadata instance generates a separate file with a top level property. This is good for build times as well as it helps with incremental compilation.
The RootCodegen file references these top level properties from the other files. I also removed the top level properties from this Codegen file as those would need to be initialized during init (which Jacoco invokes) and instead directly create the aggregated list of top level properties in the interface method.
Each of these properties are also generated in the respective module in which the components are declared. This is potentially a huge build time improvement as we've seen that the root modules become bottleneck modules as your codebase scales and you add many components.
These two changes will ensure that the initialization of the aggregated class is significantly more light weight and should avoid an issue like this from happening again.
Before
@ShowkaseRootCodegen(
numComposablesWithoutPreviewParameter = 2,
numComposablesWithPreviewParameter = 0,
numColors = 1,
numTypography = 1,
)
public class TestShowkaseRootCodegen : ShowkaseProvider {
public val componentList: List<ShowkaseBrowserComponent> =
mutableListOf<ShowkaseBrowserComponent>(
ShowkaseBrowserComponent(
group = "group1",
componentName = "name1",
componentKDoc = "",
componentKey =
"""com.airbnb.android.showkase_processor_testing_null_group1_name1_0_null""",
isDefaultStyle = false,
component = @Composable { TestComposable1() }),
)
public val colorList: List<ShowkaseBrowserColor> = listOf<ShowkaseBrowserColor>(
ShowkaseBrowserColor(
colorGroup = "color",
colorName = "name",
colorKDoc = "",
color = red)
)
public val typographyList: List<ShowkaseBrowserTypography> = listOf<ShowkaseBrowserTypography>(
ShowkaseBrowserTypography(
typographyGroup = "typography",
typographyName = "name",
typographyKDoc = "",
textStyle = title)
)
public override fun getShowkaseComponents(): List<ShowkaseBrowserComponent> = componentList
public override fun getShowkaseColors(): List<ShowkaseBrowserColor> = colorList
public override fun getShowkaseTypography(): List<ShowkaseBrowserTypography> = typographyList
}
After
@ShowkaseRootCodegen(
numComposablesWithoutPreviewParameter = 2,
numComposablesWithPreviewParameter = 0,
numColors = 1,
numTypography = 1,
)
public class TestShowkaseRootCodegen : ShowkaseProvider {
public override fun getShowkaseComponents(): List<ShowkaseBrowserComponent> {
return listOf<ShowkaseBrowserComponent>(
comairbnbandroidshowkaseprocessortestinggroup1name1,
)
}
public override fun getShowkaseColors(): List<ShowkaseBrowserColor> {
return listOf<ShowkaseBrowserColor>(
comairbnbandroidshowkaseprocessortestingcolorname,
)
}
public override fun getShowkaseTypography(): List<ShowkaseBrowserTypography> {
return listOf<ShowkaseBrowserTypography>(
comairbnbandroidshowkaseprocessortestingtypographyname,
)
}
}
// This is an auto-generated file. Please do not edit/modify this file.
package com.airbnb.android.showkase_processor_testing
import com.airbnb.android.showkase.models.ShowkaseBrowserColor
public val comairbnbandroidshowkaseprocessortestingcolorname: ShowkaseBrowserColor =
ShowkaseBrowserColor(
colorGroup = "color",
colorName = "name",
colorKDoc = "",
color = red
)
// This is an auto-generated file. Please do not edit/modify this file.
package com.airbnb.android.showkase_processor_testing
import androidx.compose.runtime.Composable
import com.airbnb.android.showkase.models.ShowkaseBrowserComponent
public val comairbnbandroidshowkaseprocessortestinggroup1name1: ShowkaseBrowserComponent =
ShowkaseBrowserComponent(
group = "group1",
componentName = "name1",
componentKDoc = "",
componentKey = """com.airbnb.android.showkase_processor_testing_null_group1_name1_0_null""",
isDefaultStyle = false,
component = @Composable { TestComposable1() }
)
// This is an auto-generated file. Please do not edit/modify this file.
package com.airbnb.android.showkase_processor_testing
import com.airbnb.android.showkase.models.ShowkaseBrowserTypography
public val comairbnbandroidshowkaseprocessortestingtypographyname: ShowkaseBrowserTypography =
ShowkaseBrowserTypography(
typographyGroup = "typography",
typographyName = "name",
typographyKDoc = "",
textStyle = title
)
We hit an issue with a Jacoco task where it wasn't able to initialize the
XRootCodegen
file anymore as our codebase had reached the limit of components it was able to support. This was specifically happening if you used Jacoco as it tries to do a few things internally that initializes each class that's going to be processed for code coverage.In this PR, I've implemented a couple changes:
ShowkaseMetadata
instance generates a separate file with a top level property. This is good for build times as well as it helps with incremental compilation.RootCodegen
file references these top level properties from the other files. I also removed the top level properties from this Codegen file as those would need to be initialized during init (which Jacoco invokes) and instead directly create the aggregated list of top level properties in the interface method.These two changes will ensure that the initialization of the aggregated class is significantly more light weight and should avoid an issue like this from happening again.
Before
After