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 00b4da89776..fe20dcb903a 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 @@ -219,6 +219,8 @@ public static boolean isSplitResolveAndLayoutWithSplitHandlers() { /** Skip checking for root component and tree-props while layout */ public static boolean isSkipRootCheckingEnabled = false; + public static boolean enableComputeLayoutAsyncAfterInsertion = true; + public static boolean shouldCompareCommonPropsInIsEquivalentTo = false; public static boolean shouldCompareRootCommonPropsInSingleComponentSection = false; diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java index b90b289bdda..c9907349315 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java +++ b/litho-widget/src/main/java/com/facebook/litho/widget/RecyclerBinder.java @@ -1388,12 +1388,19 @@ private void registerAsyncInsert(AsyncInsertOperation operation) { holder.setNewLayoutReadyListener(mAsyncLayoutReadyListener); // Otherwise, we'll kick off the layout at the end of measure if (isMeasured()) { - computeLayoutAsync(holder); + // Kicking off layout computation for all insert operations can be wasteful because some of + // them may not in the working range. We can optimize this by respecting the working range and + // postponing the layout computation to [maybeUpdateRangeOrRemeasureForMutation], which will + // be invoked when we apply batch later on. + if (ComponentsConfiguration.enableComputeLayoutAsyncAfterInsertion + || mCommitPolicy == CommitPolicy.LAYOUT_BEFORE_INSERT) { + computeLayoutAsync(holder); + } } } /** - * Moves an item from fromPosition to toPostion. If there are other pending operations on this + * Moves an item from fromPosition to toPosition. If there are other pending operations on this * binder this will only be executed when all the operations have been completed (to ensure index * consistency). */