From be77daf420a21b36b7c13280b3ba44a9ad9821a6 Mon Sep 17 00:00:00 2001 From: Fabio Carballo Date: Mon, 28 Aug 2023 08:53:15 -0700 Subject: [PATCH] Add ability to experiment between sync and non sync mount item pool Summary: After we have unified the implementation of `MountItemPool` between rendercore and litho, we are left with one single difference. Litho used synchronized pools, while rendercore didn't. For the sake of simplicity, we are going to test using non-synchronized pools in Litho as well. This behavior is only needed for *MountSpecs* as Primitives/Mountables already rely on the render core default. Reviewed By: zielinskimz Differential Revision: D48731650 fbshipit-source-id: f8e7635aaa4e16cc585e5ce8db6d47c58c003b8e --- .../com/facebook/litho/SpecGeneratedComponent.java | 6 +++++- .../litho/config/ComponentsConfiguration.java | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/litho-core/src/main/java/com/facebook/litho/SpecGeneratedComponent.java b/litho-core/src/main/java/com/facebook/litho/SpecGeneratedComponent.java index 13917d1a1ba..f6ca2fb9b5a 100644 --- a/litho-core/src/main/java/com/facebook/litho/SpecGeneratedComponent.java +++ b/litho-core/src/main/java/com/facebook/litho/SpecGeneratedComponent.java @@ -39,6 +39,7 @@ import com.facebook.litho.annotations.OnAttached; import com.facebook.litho.annotations.OnCreateTreeProp; import com.facebook.litho.annotations.OnDetached; +import com.facebook.litho.config.ComponentsConfiguration; import com.facebook.litho.debug.LithoDebugEventAttributes; import com.facebook.rendercore.ContentAllocator; import com.facebook.rendercore.MountItemsPool; @@ -776,7 +777,10 @@ public boolean canPreallocate() { */ @Override public MountItemsPool.ItemPool onCreateMountContentPool() { - return new MountItemsPool.DefaultItemPool(getPoolableContentType(), poolSize(), true); + return new MountItemsPool.DefaultItemPool( + getPoolableContentType(), + poolSize(), + ComponentsConfiguration.getDefaultComponentsConfiguration().useSyncMountPools()); } @ThreadSafe diff --git a/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java b/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java index 9bb7d593a98..9dd01b470a8 100644 --- a/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java +++ b/litho-core/src/main/java/com/facebook/litho/config/ComponentsConfiguration.java @@ -324,10 +324,16 @@ public static ComponentsConfiguration.Builder getDefaultComponentsConfigurationB private final boolean mNestedPreallocationEnabled; + private final boolean mUseSyncMountPools; + public boolean isNestedPreallocationEnabled() { return mNestedPreallocationEnabled; } + public boolean useSyncMountPools() { + return mUseSyncMountPools; + } + public boolean getUseCancelableLayoutFutures() { return mUseCancelableLayoutFutures; } @@ -358,6 +364,7 @@ private ComponentsConfiguration(ComponentsConfiguration.Builder builder) { mShouldDisableBgFgOutputs = builder.mShouldDisableBgFgOutputs; mUseIncrementalMountGapWorker = builder.mUseIncrementalMountGapWorker; mNestedPreallocationEnabled = builder.mNestedPreallocationEnabled; + mUseSyncMountPools = builder.mUseSyncItemPools; } public boolean shouldReuseOutputs() { @@ -396,6 +403,8 @@ public static class Builder { boolean mUseIncrementalMountGapWorker = IncrementalMountExtensionConfigs.useGapWorker; boolean mNestedPreallocationEnabled = false; + boolean mUseSyncItemPools = true; + protected Builder() {} public Builder useCancelableLayoutFutures(boolean enable) { @@ -438,6 +447,11 @@ public Builder useIncrementalMountGapWorker(boolean enabled) { return this; } + public Builder useSyncItemPools(boolean enabled) { + mUseSyncItemPools = enabled; + return this; + } + /** * If true, uses the root ComponentTree's mount content allows the usage of the preallocation * handler to perform preallocation for nested trees.