Skip to content

Commit 899ad82

Browse files
Fabio Carballofacebook-github-bot
authored andcommitted
Move enableDrawablePreAllocation to ComponentsConfiguration data 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
1 parent d746ab3 commit 899ad82

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

litho-core/src/main/java/com/facebook/litho/LayoutState.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public static boolean isFromSyncLayout(@RenderSource int source) {
159159
private boolean mIsCommitted;
160160

161161
private boolean mShouldProcessVisibilityOutputs;
162+
private boolean mEnableDrawablePreallocation;
162163

163164
LayoutState(
164165
int id,
@@ -173,6 +174,8 @@ public static boolean isFromSyncLayout(@RenderSource int source) {
173174
ReductionState reductionState) {
174175
mId = id;
175176
mResolveResult = resolveResult;
177+
mEnableDrawablePreallocation =
178+
mResolveResult.context.mLithoConfiguration.componentsConfig.enableDrawablePreAllocation;
176179
mSizeConstraints = sizeConstraints;
177180
mRootX = rootX;
178181
mRootY = rootY;
@@ -339,8 +342,7 @@ void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) {
339342
continue;
340343
}
341344

342-
if (ComponentsConfiguration.enableDrawablePreAllocation
343-
|| isMountableView(treeNode.getRenderUnit())) {
345+
if (mEnableDrawablePreallocation || isMountableView(treeNode.getRenderUnit())) {
344346

345347
boolean preallocated =
346348
MountItemsPool.maybePreallocateContent(
@@ -349,7 +351,7 @@ void preAllocateMountContent(boolean shouldPreallocatePerMountSpec) {
349351

350352
Log.d(
351353
"LayoutState",
352-
"Preallocation of"
354+
"Preallocation of "
353355
+ component.getSimpleName()
354356
+ (preallocated ? " succeeded" : " failed"));
355357
}

litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.kt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,12 @@ internal constructor(
7575
* every state update in a small time window. This has been proven to be an overall improvement
7676
* for performance so it's highly advised to not disable it.
7777
*/
78-
@JvmField val enableStateUpdatesBatching: Boolean = true
78+
@JvmField val enableStateUpdatesBatching: Boolean = true,
79+
/**
80+
* By default, we do not allow preallocation of [Drawable]. By turning this option on, you can
81+
* also preallocate [Drawable] mount content, when [mountContentPreallocation] is enabled.
82+
*/
83+
@JvmField val enableDrawablePreAllocation: Boolean = false
7984
) {
8085

8186
val shouldAddRootHostViewOrDisableBgFgOutputs: Boolean =
@@ -151,7 +156,6 @@ internal constructor(
151156
@JvmField var enableThreadTracingStacktrace: Boolean = false
152157

153158
@JvmField var runLooperPrepareForLayoutThreadFactory: Boolean = true
154-
@JvmField var enableDrawablePreAllocation: Boolean = false
155159

156160
@JvmField var perfBoosterFactory: LithoPerfBoosterFactory? = null
157161

@@ -239,6 +243,7 @@ internal constructor(
239243
private var shouldEnableDefaultAOSPLithoLifecycleProvider =
240244
baseConfig.shouldEnableDefaultAOSPLithoLifecycleProvider
241245
private var enableStateUpdatesBatching = baseConfig.enableStateUpdatesBatching
246+
private var enableDrawablePreAllocation = baseConfig.enableDrawablePreAllocation
242247

243248
fun shouldAddHostViewForRootComponent(enabled: Boolean) = also {
244249
shouldAddHostViewForRootComponent = enabled
@@ -280,6 +285,10 @@ internal constructor(
280285
enableStateUpdatesBatching = enabled
281286
}
282287

288+
fun enableDrawablePreAllocation(enabled: Boolean): Builder = also {
289+
enableDrawablePreAllocation = enabled
290+
}
291+
283292
fun build(): ComponentsConfiguration {
284293
return baseConfig.copy(
285294
specsApiStateUpdateDuplicateDetectionEnabled =
@@ -293,7 +302,8 @@ internal constructor(
293302
componentHostRecyclingEnabled = componentHostRecyclingEnabled,
294303
shouldEnableDefaultAOSPLithoLifecycleProvider =
295304
shouldEnableDefaultAOSPLithoLifecycleProvider,
296-
enableStateUpdatesBatching = enableStateUpdatesBatching)
305+
enableStateUpdatesBatching = enableStateUpdatesBatching,
306+
enableDrawablePreAllocation = enableDrawablePreAllocation)
297307
}
298308
}
299309
}

0 commit comments

Comments
 (0)