Skip to content

Commit

Permalink
Codeship layout caching
Browse files Browse the repository at this point in the history
Summary:
We have shipped with GK the last place where layout caching was disabled. Therefore we can codeship this change.

You will see a lot of `shouldCacheLayout=false` being deleted. This is because our `force_layout_caching` QE was overriding them, and now we know it's safe to delete them.

I will land this after the cut though.

Reviewed By: adityasharat

Differential Revision: D60445765

fbshipit-source-id: dc55e6c2661a6fa90a9ea90bceb38e6c8d53833f
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Aug 1, 2024
1 parent 97bcf0a commit 6f11ff5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,7 @@ public ScopedComponentInfo getScopedComponentInfo() {
}

public boolean shouldCacheLayouts() {
return isReconciliationEnabled()
&& mLithoConfiguration.componentsConfig.getShouldCacheLayouts();
return isReconciliationEnabled();
}

public final boolean shouldUseNonRebindingEventHandlers() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import com.facebook.rendercore.visibility.VisibilityBoundsTransformer
*/
data class ComponentsConfiguration
internal constructor(
val shouldCacheLayouts: Boolean = true,
val disableNestedTreeCaching: Boolean = true,
val shouldAddHostViewForRootComponent: Boolean = false,
@JvmField
Expand Down Expand Up @@ -332,7 +331,6 @@ internal constructor(
class Builder internal constructor(private var baseConfig: ComponentsConfiguration) {

private var shouldAddHostViewForRootComponent = baseConfig.shouldAddHostViewForRootComponent
private var shouldCacheLayouts = baseConfig.shouldCacheLayouts
private var isReconciliationEnabled = baseConfig.isReconciliationEnabled
private var preAllocationHandler = baseConfig.preAllocationHandler
private var incrementalMountEnabled = baseConfig.incrementalMountEnabled
Expand Down Expand Up @@ -372,8 +370,6 @@ internal constructor(
shouldAddHostViewForRootComponent = enabled
}

fun shouldCacheLayouts(enabled: Boolean): Builder = also { shouldCacheLayouts = enabled }

fun isReconciliationEnabled(enabled: Boolean): Builder = also {
isReconciliationEnabled = enabled
}
Expand Down Expand Up @@ -483,7 +479,6 @@ internal constructor(

fun build(): ComponentsConfiguration {
return baseConfig.copy(
shouldCacheLayouts = shouldCacheLayouts,
shouldAddHostViewForRootComponent = shouldAddHostViewForRootComponent,
isReconciliationEnabled = isReconciliationEnabled,
preAllocationHandler = preAllocationHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,30 @@ class ComponentsConfigurationTest {

@Test
fun testSetFlagThroughComponentConfigToComponentTree() {
ComponentsConfiguration.defaultInstance = defaultConfiguration.copy(shouldCacheLayouts = true)
ComponentsConfiguration.defaultInstance =
defaultConfiguration.copy(isReconciliationEnabled = true)
val componentTree =
ComponentTree.create(componentContext)
.componentsConfiguration(ComponentsConfiguration.defaultInstance)
.build()
val componentsConfiguration = componentTree.context.mLithoConfiguration.componentsConfig

assertThat(componentsConfiguration.shouldCacheLayouts).isTrue
assertThat(componentsConfiguration.isReconciliationEnabled).isTrue
ComponentsConfiguration.defaultInstance = defaultConfiguration
}

@Test
fun testSetFlagThroughComponentConfigToComponentTreeWithRecyclerCollectionComponent() {
ComponentsConfiguration.defaultInstance = defaultConfiguration.copy(shouldCacheLayouts = false)
ComponentsConfiguration.defaultInstance =
defaultConfiguration.copy(isReconciliationEnabled = false)

val recyclerBinderConfiguration =
RecyclerBinderConfiguration.create()
.recyclerBinderConfig(
RecyclerBinderConfig(
componentsConfiguration =
ComponentsConfiguration.defaultInstance.copy(shouldCacheLayouts = true)))
ComponentsConfiguration.defaultInstance.copy(
isReconciliationEnabled = true)))
.build()

legacyLithoViewRule
Expand All @@ -92,17 +95,19 @@ class ComponentsConfigurationTest {
assertThat(childView).isNotNull
val componentsConfiguration =
childView?.componentTree?.context?.mLithoConfiguration?.componentsConfig
assertThat(componentsConfiguration?.shouldCacheLayouts).isTrue
assertThat(componentsConfiguration?.isReconciliationEnabled).isTrue
ComponentsConfiguration.defaultInstance = defaultConfiguration
}

@Test
fun testOverrideDefaultBuilder() {
ComponentsConfiguration.defaultInstance = defaultConfiguration.copy(shouldCacheLayouts = true)
assertThat(ComponentsConfiguration.defaultInstance.shouldCacheLayouts).isTrue
ComponentsConfiguration.defaultInstance =
defaultConfiguration.copy(isReconciliationEnabled = true)
assertThat(ComponentsConfiguration.defaultInstance.isReconciliationEnabled).isTrue

ComponentsConfiguration.defaultInstance = defaultConfiguration.copy(shouldCacheLayouts = false)
assertThat(ComponentsConfiguration.defaultInstance.shouldCacheLayouts).isFalse
ComponentsConfiguration.defaultInstance =
defaultConfiguration.copy(isReconciliationEnabled = false)
assertThat(ComponentsConfiguration.defaultInstance.isReconciliationEnabled).isFalse

ComponentsConfiguration.defaultInstance = defaultConfiguration
}
Expand Down

0 comments on commit 6f11ff5

Please sign in to comment.