Skip to content

Commit

Permalink
[Perf/codesize] Reland: Reduce constraint member reads during layout
Browse files Browse the repository at this point in the history
This reverts commit 2132a0c.
  • Loading branch information
jonahwilliams committed Feb 28, 2020
1 parent 7011d30 commit 213027d
Show file tree
Hide file tree
Showing 32 changed files with 41 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/flutter/lib/src/cupertino/action_sheet.dart
Expand Up @@ -668,6 +668,7 @@ class _RenderCupertinoAlert extends RenderBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final bool hasDivider = contentSection.getMaxIntrinsicHeight(constraints.maxWidth) > 0.0
&& actionsSection.getMaxIntrinsicHeight(constraints.maxWidth) > 0.0;
final double dividerThickness = hasDivider ? _dividerThickness : 0.0;
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/cupertino/dialog.dart
Expand Up @@ -1540,6 +1540,7 @@ class _RenderCupertinoDialogActions extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (_isSingleButtonRow(dialogWidth)) {
if (childCount == 1) {
// We have 1 button. Our size is the width of the dialog and the height
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/cupertino/refresh.dart
Expand Up @@ -104,6 +104,7 @@ class _RenderCupertinoSliverRefresh extends RenderSliver

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// Only pulling to refresh from the top is currently supported.
assert(constraints.axisDirection == AxisDirection.down);
assert(constraints.growthDirection == GrowthDirection.forward);
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/cupertino/segmented_control.dart
Expand Up @@ -628,6 +628,7 @@ class _RenderSegmentedControl<T> extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
double maxHeight = _kMinSegmentedControlHeight;

double childWidth = constraints.minWidth / childCount;
Expand Down
Expand Up @@ -828,6 +828,7 @@ class _RenderSegmentedControl<T> extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
double childWidth = (constraints.minWidth - totalSeparatorWidth) / childCount;
double maxHeight = _kMinSegmentedControlHeight;

Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/cupertino/text_selection.dart
Expand Up @@ -159,6 +159,7 @@ class _ToolbarRenderBox extends RenderShiftedBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
size = constraints.biggest;

if (child == null) {
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/app_bar.dart
Expand Up @@ -1347,6 +1347,7 @@ class _RenderAppBarTitleBox extends RenderAligningShiftedBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final BoxConstraints innerConstraints = constraints.copyWith(maxHeight: double.infinity);
child.layout(innerConstraints, parentUsesSize: true);
size = constraints.constrain(child.size);
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/button.dart
Expand Up @@ -509,6 +509,7 @@ class _RenderInputPadding extends RenderShiftedBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child.layout(constraints, parentUsesSize: true);
final double height = math.max(child.size.width, minSize.width);
Expand Down
Expand Up @@ -582,6 +582,7 @@ class _RenderChildOverflowBox extends RenderAligningShiftedBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child.layout(const BoxConstraints(), parentUsesSize: true);
size = Size(
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/input_decorator.dart
Expand Up @@ -1257,6 +1257,7 @@ class _RenderDecoration extends RenderBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_labelTransform = null;
final _RenderDecorationLayout layout = _layout(constraints);

Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/material/list_tile.dart
Expand Up @@ -1328,6 +1328,7 @@ class _RenderListTile extends RenderBox {
// https://material.io/design/components/lists.html#specs
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final bool hasLeading = leading != null;
final bool hasSubtitle = subtitle != null;
final bool hasTrailing = trailing != null;
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/rendering/animated_size.dart
Expand Up @@ -170,7 +170,7 @@ class RenderAnimatedSize extends RenderAligningShiftedBox {
void performLayout() {
_lastValue = _controller.value;
_hasVisualOverflow = false;

final BoxConstraints constraints = this.constraints;
if (child == null || constraints.isTight) {
_controller.stop();
size = _sizeTween.begin = _sizeTween.end = constraints.smallest;
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/editable.dart
Expand Up @@ -1743,6 +1743,7 @@ class RenderEditable extends RenderBox with RelayoutWhenSystemFontsChangeMixin {
}
@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_layoutText(minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
_caretPrototype = _getCaretPrototype;
_selectionRects = null;
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/rendering/flex.dart
Expand Up @@ -636,6 +636,8 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
@override
void performLayout() {
assert(_debugHasNecessaryDirections);
final BoxConstraints constraints = this.constraints;

// Determine used flex factor, size inflexible items, calculate free space.
int totalFlex = 0;
int totalChildren = 0;
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/flow.dart
Expand Up @@ -279,6 +279,7 @@ class RenderFlow extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
size = _getSize(constraints);
int i = 0;
_randomAccessChildren.clear();
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/list_body.dart
Expand Up @@ -63,6 +63,7 @@ class RenderListBody extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
assert(() {
switch (mainAxis) {
case Axis.horizontal:
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/paragraph.dart
Expand Up @@ -575,6 +575,7 @@ class RenderParagraph extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_layoutChildren(constraints);
_layoutTextWithConstraints(constraints);
_setParentData();
Expand Down
2 changes: 2 additions & 0 deletions packages/flutter/lib/src/rendering/proxy_box.dart
Expand Up @@ -260,6 +260,7 @@ class RenderConstrainedBox extends RenderProxyBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
child.layout(_additionalConstraints.enforce(constraints), parentUsesSize: true);
size = child.size;
Expand Down Expand Up @@ -351,6 +352,7 @@ class RenderLimitedBox extends RenderProxyBox {
@override
void performLayout() {
if (child != null) {
final BoxConstraints constraints = this.constraints;
child.layout(_limitConstraints(constraints), parentUsesSize: true);
size = constraints.constrain(child.size);
} else {
Expand Down
4 changes: 4 additions & 0 deletions packages/flutter/lib/src/rendering/shifted_box.dart
Expand Up @@ -193,6 +193,7 @@ class RenderPadding extends RenderShiftedBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_resolve();
assert(_resolvedPadding != null);
if (child == null) {
Expand Down Expand Up @@ -385,6 +386,7 @@ class RenderPositionedBox extends RenderAligningShiftedBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final bool shrinkWrapWidth = _widthFactor != null || constraints.maxWidth == double.infinity;
final bool shrinkWrapHeight = _heightFactor != null || constraints.maxHeight == double.infinity;

Expand Down Expand Up @@ -649,6 +651,7 @@ class RenderUnconstrainedBox extends RenderAligningShiftedBox with DebugOverflow

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child != null) {
// Let the child lay itself out at it's "natural" size, but if
// constrainedAxis is non-null, keep any constraints on that axis.
Expand Down Expand Up @@ -1183,6 +1186,7 @@ class RenderBaseline extends RenderShiftedBox {
@override
void performLayout() {
if (child != null) {
final BoxConstraints constraints = this.constraints;
child.layout(constraints.loosen(), parentUsesSize: true);
final double childBaseline = child.getDistanceToBaseline(baselineType);
final double actualBaseline = baseline;
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/sliver.dart
Expand Up @@ -1813,6 +1813,7 @@ class RenderSliverToBoxAdapter extends RenderSliverSingleBoxAdapter {
geometry = SliverGeometry.zero;
return;
}
final SliverConstraints constraints = this.constraints;
child.layout(constraints.asBoxConstraints(), parentUsesSize: true);
double childExtent;
switch (constraints.axis) {
Expand Down
3 changes: 3 additions & 0 deletions packages/flutter/lib/src/rendering/sliver_fill.dart
Expand Up @@ -87,6 +87,7 @@ class RenderSliverFillRemainingWithScrollable extends RenderSliverSingleBoxAdapt

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// TODO(Piinks): This may fill too much space for NestedScrollView, https://github.com/flutter/flutter/issues/46028
final double extent = constraints.remainingPaintExtent - math.min(constraints.overlap, 0.0);

Expand Down Expand Up @@ -137,6 +138,7 @@ class RenderSliverFillRemaining extends RenderSliverSingleBoxAdapter {

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// The remaining space in the viewportMainAxisExtent. Can be <= 0 if we have
// scrolled beyond the extent of the screen.
double extent = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent;
Expand Down Expand Up @@ -209,6 +211,7 @@ class RenderSliverFillRemainingAndOverscroll extends RenderSliverSingleBoxAdapte

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
// The remaining space in the viewportMainAxisExtent. Can be <= 0 if we have
// scrolled beyond the extent of the screen.
double extent = constraints.viewportMainAxisExtent - constraints.precedingScrollExtent;
Expand Down
Expand Up @@ -164,6 +164,7 @@ abstract class RenderSliverFixedExtentBoxAdaptor extends RenderSliverMultiBoxAda

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
childManager.didStartLayout();
childManager.setDidUnderflow(false);

Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/sliver_grid.dart
Expand Up @@ -511,6 +511,7 @@ class RenderSliverGrid extends RenderSliverMultiBoxAdaptor {

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
childManager.didStartLayout();
childManager.setDidUnderflow(false);

Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/sliver_list.dart
Expand Up @@ -44,6 +44,7 @@ class RenderSliverList extends RenderSliverMultiBoxAdaptor {

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
childManager.didStartLayout();
childManager.setDidUnderflow(false);

Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/sliver_padding.dart
Expand Up @@ -118,6 +118,7 @@ abstract class RenderSliverEdgeInsetsPadding extends RenderSliver with RenderObj

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
assert(resolvedPadding != null);
final double beforePadding = this.beforePadding;
final double afterPadding = this.afterPadding;
Expand Down
Expand Up @@ -331,6 +331,7 @@ abstract class RenderSliverScrollingPersistentHeader extends RenderSliverPersist

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
layoutChild(constraints.scrollOffset, maxExtent);
final double paintExtent = maxExtent - constraints.scrollOffset;
Expand Down Expand Up @@ -369,6 +370,7 @@ abstract class RenderSliverPinnedPersistentHeader extends RenderSliverPersistent

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
final bool overlapsContent = constraints.overlap > 0.0;
excludeFromSemanticsScrolling = overlapsContent || (constraints.scrollOffset > maxExtent - minExtent);
Expand Down Expand Up @@ -552,6 +554,7 @@ abstract class RenderSliverFloatingPersistentHeader extends RenderSliverPersiste

@override
void performLayout() {
final SliverConstraints constraints = this.constraints;
final double maxExtent = this.maxExtent;
if (_lastActualScrollOffset != null && // We've laid out at least once to get an initial position, and either
((constraints.scrollOffset < _lastActualScrollOffset) || // we are scrolling back, so should reveal, or
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/stack.dart
Expand Up @@ -517,6 +517,7 @@ class RenderStack extends RenderBox

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
_resolve();
assert(_resolvedAlignment != null);
_hasVisualOverflow = false;
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/table.dart
Expand Up @@ -992,6 +992,7 @@ class RenderTable extends RenderBox {

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
final int rows = this.rows;
final int columns = this.columns;
assert(_children.length == rows * columns);
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/viewport.dart
Expand Up @@ -1699,6 +1699,7 @@ class RenderShrinkWrappingViewport extends RenderViewportBase<SliverLogicalConta

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (firstChild == null) {
switch (axis) {
case Axis.vertical:
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/rendering/wrap.dart
Expand Up @@ -565,6 +565,7 @@ class RenderWrap extends RenderBox with ContainerRenderObjectMixin<RenderBox, Wr

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
assert(_debugHasNecessaryDirections);
_hasVisualOverflow = false;
RenderBox child = firstChild;
Expand Down
1 change: 1 addition & 0 deletions packages/flutter/lib/src/widgets/layout_builder.dart
Expand Up @@ -238,6 +238,7 @@ class _RenderLayoutBuilder extends RenderBox with RenderObjectWithChildMixin<Ren

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
layoutAndBuildChild();
if (child != null) {
child.layout(constraints, parentUsesSize: true);
Expand Down
Expand Up @@ -505,6 +505,7 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix

@override
void performLayout() {
final BoxConstraints constraints = this.constraints;
if (child == null) {
size = constraints.smallest;
} else {
Expand Down

0 comments on commit 213027d

Please sign in to comment.