Skip to content

Commit

Permalink
Ship lazy layout for exact measurements
Browse files Browse the repository at this point in the history
Summary:
This is part of the fix for android's double measure bug. It postpones ComponentLayout calculation from measure to layout is the measured dimensions are exact: this means that if we get remeasured with different exact measurements, we don't compute two layouts.

Deltoid results: https://fburl.com/deltoid3/ylrbxcpu (big-ish improvements for watch tab, small improvements for groups mall)

Reviewed By: IanChilds

Differential Revision: D8434171

fbshipit-source-id: 85b5c9aa2abd960d264071d6d358ecbbb6e50c78
  • Loading branch information
astreet authored and facebook-github-bot committed Jun 15, 2018
1 parent 3e9cb8a commit bb4dbd5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 32 deletions.
17 changes: 9 additions & 8 deletions litho-core/src/main/java/com/facebook/litho/LithoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -291,14 +291,15 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
mTemporaryDetachedComponent = null;
}

if (ComponentsConfiguration.lazyLayoutForExactSpec) {
if (!mForceLayout
&& SizeSpec.getMode(widthMeasureSpec) == SizeSpec.EXACTLY
&& SizeSpec.getMode(heightMeasureSpec) == SizeSpec.EXACTLY) {
mDoMeasureInLayout = true;
setMeasuredDimension(width, height);
return;
}
if (!mForceLayout
&& SizeSpec.getMode(widthMeasureSpec) == SizeSpec.EXACTLY
&& SizeSpec.getMode(heightMeasureSpec) == SizeSpec.EXACTLY) {
// If the measurements are exact, postpone LayoutState calculation from measure to layout.
// This is part of the fix for android's double measure bug. Doing this means that if we get
// remeasured with different exact measurements, we don't compute two layouts.
mDoMeasureInLayout = true;
setMeasuredDimension(width, height);
return;
}

mIsMeasuring = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@ public class ComponentsConfiguration {
/** Default for ComponentHost#hasOverlappingRendering. */
public static boolean hostHasOverlappingRendering = true;

/**
* Don't compute LayoutState in LithoView#onMeasure if measure specs are exact: wait for onLayout
* instead.
*/
public static boolean lazyLayoutForExactSpec = false;

/** Enable variable BatchSize for ArrayBatchAllocator */
public static boolean variableArrayBatchAllocatorEnabled = false;

Expand Down
18 changes: 0 additions & 18 deletions litho-it/src/test/java/com/facebook/litho/LithoViewTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ protected Component onCreateLayout(ComponentContext c) {
@After
public void tearDown() {
ComponentsConfiguration.doubleMeasureCorrection = false;
ComponentsConfiguration.lazyLayoutForExactSpec = false;
ComponentsConfiguration.isDebugModeEnabled = ComponentsConfiguration.IS_INTERNAL_BUILD;
}

Expand Down Expand Up @@ -278,23 +277,8 @@ public void testNoCorrectionWithConfigOff() {
assertThat(mLithoView.getMeasuredHeight()).isEqualTo(100);
}

@Test
public void testMeasureComputesLayoutStateWhenSpecsAreExactNotInConfig() {
ComponentsConfiguration.lazyLayoutForExactSpec = false;

mLithoView = new LithoView(RuntimeEnvironment.application);
mLithoView.setComponent(TestDrawableComponent.create(mLithoView.getComponentContext()).build());
mLithoView.measure(makeMeasureSpec(100, EXACTLY), makeMeasureSpec(100, EXACTLY));

assertThat(mLithoView.getMeasuredWidth()).isEqualTo(100);
assertThat(mLithoView.getMeasuredHeight()).isEqualTo(100);
assertThat(mLithoView.getComponentTree().getMainThreadLayoutState()).isNotNull();
}

@Test
public void testMeasureDoesNotComputeLayoutStateWhenSpecsAreExact() {
ComponentsConfiguration.lazyLayoutForExactSpec = true;

mLithoView = new LithoView(RuntimeEnvironment.application);
mLithoView.setComponent(TestDrawableComponent.create(mLithoView.getComponentContext()).build());
mLithoView.measure(makeMeasureSpec(100, EXACTLY), makeMeasureSpec(100, EXACTLY));
Expand All @@ -312,8 +296,6 @@ public void testMeasureDoesNotComputeLayoutStateWhenSpecsAreExact() {

@Test
public void testMeasureComputesLayoutStateWhenSpecsAreNotExact() {
ComponentsConfiguration.lazyLayoutForExactSpec = true;

mLithoView = new LithoView(RuntimeEnvironment.application);
mLithoView.setComponent(
TestDrawableComponent.create(mLithoView.getComponentContext()).heightPx(100).build());
Expand Down

0 comments on commit bb4dbd5

Please sign in to comment.