Skip to content

Commit

Permalink
Move enableDrawablePreAllocation to ComponentsConfiguration data …
Browse files Browse the repository at this point in the history
…class

Summary:
This diff moves the static `enableDrawablePreAllocation` to inside the values of the `ComponentsConfiguration`.

This will allow us to enable this at the `ComponentTree` level and do testing at the surface level (which I aim to do in the StoriesViewer).

Reviewed By: larrytjok

Differential Revision: D52958863

fbshipit-source-id: 4065795bd10490fe1e77c6ffde27e1b41c06a784
  • Loading branch information
Fabio Carballo authored and facebook-github-bot committed Jan 23, 2024
1 parent d746ab3 commit 899ad82
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
8 changes: 5 additions & 3 deletions litho-core/src/main/java/com/facebook/litho/LayoutState.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public static boolean isFromSyncLayout(@RenderSource int source) {
private boolean mIsCommitted;

private boolean mShouldProcessVisibilityOutputs;
private boolean mEnableDrawablePreallocation;

LayoutState(
int id,
Expand All @@ -173,6 +174,8 @@ public static boolean isFromSyncLayout(@RenderSource int source) {
ReductionState reductionState) {
mId = id;
mResolveResult = resolveResult;
mEnableDrawablePreallocation =
mResolveResult.context.mLithoConfiguration.componentsConfig.enableDrawablePreAllocation;
mSizeConstraints = sizeConstraints;
mRootX = rootX;
mRootY = rootY;
Expand Down Expand Up @@ -339,8 +342,7 @@ void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) {
continue;
}

if (ComponentsConfiguration.enableDrawablePreAllocation
|| isMountableView(treeNode.getRenderUnit())) {
if (mEnableDrawablePreallocation || isMountableView(treeNode.getRenderUnit())) {

boolean preallocated =
MountItemsPool.maybePreallocateContent(
Expand All @@ -349,7 +351,7 @@ void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) {

Log.d(
"LayoutState",
"Preallocation of"
"Preallocation of "
+ component.getSimpleName()
+ (preallocated ? " succeeded" : " failed"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ internal constructor(
* every state update in a small time window. This has been proven to be an overall improvement
* for performance so it's highly advised to not disable it.
*/
@JvmField val enableStateUpdatesBatching: Boolean = true
@JvmField val enableStateUpdatesBatching: Boolean = true,
/**
* By default, we do not allow preallocation of [Drawable]. By turning this option on, you can
* also preallocate [Drawable] mount content, when [mountContentPreallocation] is enabled.
*/
@JvmField val enableDrawablePreAllocation: Boolean = false
) {

val shouldAddRootHostViewOrDisableBgFgOutputs: Boolean =
Expand Down Expand Up @@ -151,7 +156,6 @@ internal constructor(
@JvmField var enableThreadTracingStacktrace: Boolean = false

@JvmField var runLooperPrepareForLayoutThreadFactory: Boolean = true
@JvmField var enableDrawablePreAllocation: Boolean = false

@JvmField var perfBoosterFactory: LithoPerfBoosterFactory? = null

Expand Down Expand Up @@ -239,6 +243,7 @@ internal constructor(
private var shouldEnableDefaultAOSPLithoLifecycleProvider =
baseConfig.shouldEnableDefaultAOSPLithoLifecycleProvider
private var enableStateUpdatesBatching = baseConfig.enableStateUpdatesBatching
private var enableDrawablePreAllocation = baseConfig.enableDrawablePreAllocation

fun shouldAddHostViewForRootComponent(enabled: Boolean) = also {
shouldAddHostViewForRootComponent = enabled
Expand Down Expand Up @@ -280,6 +285,10 @@ internal constructor(
enableStateUpdatesBatching = enabled
}

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

fun build(): ComponentsConfiguration {
return baseConfig.copy(
specsApiStateUpdateDuplicateDetectionEnabled =
Expand All @@ -293,7 +302,8 @@ internal constructor(
componentHostRecyclingEnabled = componentHostRecyclingEnabled,
shouldEnableDefaultAOSPLithoLifecycleProvider =
shouldEnableDefaultAOSPLithoLifecycleProvider,
enableStateUpdatesBatching = enableStateUpdatesBatching)
enableStateUpdatesBatching = enableStateUpdatesBatching,
enableDrawablePreAllocation = enableDrawablePreAllocation)
}
}
}

0 comments on commit 899ad82

Please sign in to comment.