Skip to content

Commit

Permalink
Disable layout calculation after async insertion to respect the worki…
Browse files Browse the repository at this point in the history
…ng range

Summary:
## Context

I observed that kicking off layout calculation right after async insertion will lead to a problem, where those items out of working range will be released immediately which can be a wasteful. We could improve this by respecting the working range and only kick off layout calculation for those items in the range. Will gate this change in the follow up diff and run experiment.

Reviewed By: adityasharat

Differential Revision: D49501675

fbshipit-source-id: 6fa8e91224d92eec9a48c277775dd63076cf4cf2
  • Loading branch information
Andrew Wang authored and facebook-github-bot committed Sep 25, 2023
1 parent ad720b0 commit 3cbabc2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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).
*/
Expand Down

0 comments on commit 3cbabc2

Please sign in to comment.