[CSS Grid Layout] Do not grow tracks when the growth factor is 0
authorsvillar@igalia.com <svillar@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Sep 2014 08:37:10 +0000 (08:37 +0000)
committersvillar@igalia.com <svillar@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 Sep 2014 08:37:10 +0000 (08:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=136575

Reviewed by Darin Adler.

A couple of performance optimizations for the track sizing
algorithm. On the one hand we avoid the computation of the
available logical space share if the track has no growth potential
(the current breadth is the maximum breadth) and on the other
hand, we avoid calling RenderGrid::distributeSpaceToTracks() if
the available logical space is not greater than 0.

The combined effect of these two changes is an impressive +16%
improvement in auto-grid-lots-of-data.html performance test.

No new tests as there is no change in the functionality.

* rendering/RenderGrid.cpp:
(WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems):
(WebCore::RenderGrid::distributeSpaceToTracks):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@173868 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderGrid.cpp

index 68e2da9..d58de5a 100644 (file)
@@ -1,3 +1,26 @@
+2014-09-15  Sergio Villar Senin  <svillar@igalia.com>
+
+        [CSS Grid Layout] Do not grow tracks when the growth factor is 0
+        https://bugs.webkit.org/show_bug.cgi?id=136575
+
+        Reviewed by Darin Adler.
+
+        A couple of performance optimizations for the track sizing
+        algorithm. On the one hand we avoid the computation of the
+        available logical space share if the track has no growth potential
+        (the current breadth is the maximum breadth) and on the other
+        hand, we avoid calling RenderGrid::distributeSpaceToTracks() if
+        the available logical space is not greater than 0.
+
+        The combined effect of these two changes is an impressive +16%
+        improvement in auto-grid-lots-of-data.html performance test.
+
+        No new tests as there is no change in the functionality.
+
+        * rendering/RenderGrid.cpp:
+        (WebCore::RenderGrid::resolveContentBasedTrackSizingFunctionsForItems):
+        (WebCore::RenderGrid::distributeSpaceToTracks):
+
 2014-09-23  Ion Rosca  <rosca@adobe.com>
 
         [CSS Blending] The composited layers isolated by the page group should blend with the default white background color.
index 659f664..e51f16b 100644 (file)
@@ -609,7 +609,10 @@ void RenderGrid::resolveContentBasedTrackSizingFunctionsForItems(GridTrackSizing
     }
 
     // FIXME: We should pass different values for |tracksForGrowthAboveMaxBreadth|.
-    distributeSpaceToTracks(sizingData.filteredTracks, &sizingData.filteredTracks, trackGetter, trackGrowthFunction, sizingData, additionalBreadthSpace);
+    // Specs mandate to floor additionalBreadthSpace (extra-space in specs) to 0. Instead we directly avoid the function
+    // call in those cases as it will be a noop in terms of track sizing.
+    if (additionalBreadthSpace > 0)
+        distributeSpaceToTracks(sizingData.filteredTracks, &sizingData.filteredTracks, trackGetter, trackGrowthFunction, sizingData, additionalBreadthSpace);
 }
 
 static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTrack* track2)
@@ -619,6 +622,7 @@ static bool sortByGridTrackGrowthPotential(const GridTrack* track1, const GridTr
 
 void RenderGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<GridTrack*>* tracksForGrowthAboveMaxBreadth, AccumulatorGetter trackGetter, AccumulatorGrowFunction trackGrowthFunction, GridSizingData& sizingData, LayoutUnit& availableLogicalSpace)
 {
+    ASSERT(availableLogicalSpace > 0);
     std::sort(tracks.begin(), tracks.end(), sortByGridTrackGrowthPotential);
 
     size_t tracksSize = tracks.size();
@@ -626,12 +630,16 @@ void RenderGrid::distributeSpaceToTracks(Vector<GridTrack*>& tracks, Vector<Grid
 
     for (size_t i = 0; i < tracksSize; ++i) {
         GridTrack& track = *tracks[i];
-        LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksSize - i);
         LayoutUnit trackBreadth = (tracks[i]->*trackGetter)();
-        LayoutUnit growthShare = std::max(LayoutUnit(), std::min(availableLogicalSpaceShare, track.m_maxBreadth - trackBreadth));
-        // We should never shrink any grid track or else we can't guarantee we abide by our min-sizing function.
-        sizingData.distributeTrackVector[i] = trackBreadth + growthShare;
-        availableLogicalSpace -= growthShare;
+        LayoutUnit trackGrowthPotential = track.m_maxBreadth - trackBreadth;
+        sizingData.distributeTrackVector[i] = trackBreadth;
+        if (trackGrowthPotential > 0) {
+            LayoutUnit availableLogicalSpaceShare = availableLogicalSpace / (tracksSize - i);
+            LayoutUnit growthShare = std::min(availableLogicalSpaceShare, trackGrowthPotential);
+            // We should never shrink any grid track or else we can't guarantee we abide by our min-sizing function.
+            sizingData.distributeTrackVector[i] += growthShare;
+            availableLogicalSpace -= growthShare;
+        }
     }
 
     if (availableLogicalSpace > 0 && tracksForGrowthAboveMaxBreadth) {