Commit a4099805 authored by svillar@igalia.com's avatar svillar@igalia.com

Use a Vector instead of HashSet to computed the orderValues in RenderFlexibleBox

https://bugs.webkit.org/show_bug.cgi?id=118620

Reviewed by Antti Koivisto.

PerformanceTests:

From Blink r152960 by <ojan@chromium.org>

New performance test for layouts in flexboxes.

* Layout/flexbox-lots-of-data.html: Added.

Source/WebCore:

Turns out that order is extremelly uncommon so using a Vector is
much less expensive. This also special-cases the much common case
of only having order of value 0 by using Vectors with just one
preallocated member.

Also added the performance test that shows a ~1% win when using a
vector instead of the HashSet.

* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::OrderIterator::setOrderValues):
(WebCore::RenderFlexibleBox::layoutBlock):
(WebCore::RenderFlexibleBox::computeMainAxisPreferredSizes):
* rendering/RenderFlexibleBox.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@157916 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 2343e28c
2013-10-14 Sergio Villar Senin <svillar@igalia.com>
Use a Vector instead of HashSet to computed the orderValues in RenderFlexibleBox
https://bugs.webkit.org/show_bug.cgi?id=118620
Reviewed by Antti Koivisto.
From Blink r152960 by <ojan@chromium.org>
New performance test for layouts in flexboxes.
* Layout/flexbox-lots-of-data.html: Added.
2013-10-06 Ryosuke Niwa <rniwa@webkit.org>
DoYouEvenBench: Make it work on Internet Explorer 11 Release Preview
......
This diff is collapsed.
2013-10-14 Sergio Villar Senin <svillar@igalia.com>
Use a Vector instead of HashSet to computed the orderValues in RenderFlexibleBox
https://bugs.webkit.org/show_bug.cgi?id=118620
Reviewed by Antti Koivisto.
Turns out that order is extremelly uncommon so using a Vector is
much less expensive. This also special-cases the much common case
of only having order of value 0 by using Vectors with just one
preallocated member.
Also added the performance test that shows a ~1% win when using a
vector instead of the HashSet.
* rendering/RenderFlexibleBox.cpp:
(WebCore::RenderFlexibleBox::OrderIterator::setOrderValues):
(WebCore::RenderFlexibleBox::layoutBlock):
(WebCore::RenderFlexibleBox::computeMainAxisPreferredSizes):
* rendering/RenderFlexibleBox.h:
2013-10-23 ChangSeok Oh <changseok.oh@collabora.com>
Unreviewed build fix since r157823.
......
......@@ -39,16 +39,6 @@
namespace WebCore {
// Normally, -1 and 0 are not valid in a HashSet, but these are relatively likely order: values. Instead,
// we make the two smallest int values invalid order: values (in the css parser code we clamp them to
// int min + 2).
struct RenderFlexibleBox::OrderHashTraits : WTF::GenericHashTraits<int> {
static const bool emptyValueIsZero = false;
static int emptyValue() { return std::numeric_limits<int>::min(); }
static void constructDeletedValue(int& slot) { slot = std::numeric_limits<int>::min() + 1; }
static bool isDeletedValue(int value) { return value == std::numeric_limits<int>::min() + 1; }
};
RenderFlexibleBox::OrderIterator::OrderIterator(const RenderFlexibleBox* flexibleBox)
: m_flexibleBox(flexibleBox)
, m_currentChild(0)
......@@ -56,11 +46,16 @@ RenderFlexibleBox::OrderIterator::OrderIterator(const RenderFlexibleBox* flexibl
{
}
void RenderFlexibleBox::OrderIterator::setOrderValues(const OrderHashSet& orderValues)
void RenderFlexibleBox::OrderIterator::setOrderValues(const OrderValues& orderValues)
{
reset();
copyToVector(orderValues, m_orderValues);
m_orderValues = orderValues;
if (m_orderValues.size() < 2)
return;
std::sort(m_orderValues.begin(), m_orderValues.end());
auto nextElement = std::unique(m_orderValues.begin(), m_orderValues.end());
m_orderValues.shrinkCapacity(nextElement - m_orderValues.begin());
}
RenderBox* RenderFlexibleBox::OrderIterator::first()
......@@ -348,7 +343,7 @@ void RenderFlexibleBox::layoutBlock(bool relayoutChildren, LayoutUnit)
dirtyForLayoutFromPercentageHeightDescendants();
Vector<LineContext> lineContexts;
OrderHashSet orderValues;
OrderIterator::OrderValues orderValues;
computeMainAxisPreferredSizes(orderValues);
m_orderIterator.setOrderValues(orderValues);
......@@ -908,10 +903,16 @@ LayoutUnit RenderFlexibleBox::computeChildMarginValue(const Length& margin)
return minimumValueForLength(margin, availableSize);
}
void RenderFlexibleBox::computeMainAxisPreferredSizes(OrderHashSet& orderValues)
void RenderFlexibleBox::computeMainAxisPreferredSizes(OrderIterator::OrderValues& orderValues)
{
ASSERT(orderValues.isEmpty());
for (RenderBox* child = firstChildBox(); child; child = child->nextSiblingBox()) {
orderValues.add(child->style()->order());
// Avoid growing the vector for the common-case default value of 0. This optimizes the most common case which is
// one or a few values with the default order 0
int order = child->style()->order();
if (orderValues.isEmpty() || orderValues.last() != order)
orderValues.append(order);
if (child->isOutOfFlowPositioned())
continue;
......
......@@ -73,14 +73,13 @@ private:
NoFlipForRowReverse,
};
struct OrderHashTraits;
typedef HashSet<int, DefaultHash<int>::Hash, OrderHashTraits> OrderHashSet;
class OrderIterator {
WTF_MAKE_NONCOPYABLE(OrderIterator);
public:
typedef Vector<int, 1> OrderValues;
OrderIterator(const RenderFlexibleBox*);
void setOrderValues(const OrderHashSet&);
void setOrderValues(const OrderValues&);
RenderBox* currentChild() const { return m_currentChild; }
RenderBox* first();
RenderBox* next();
......@@ -89,7 +88,7 @@ private:
private:
const RenderFlexibleBox* m_flexibleBox;
RenderBox* m_currentChild;
Vector<int> m_orderValues;
OrderValues m_orderValues;
Vector<int>::const_iterator m_orderValuesIterator;
};
......@@ -153,7 +152,7 @@ private:
LayoutUnit marginBoxAscentForChild(RenderBox&);
LayoutUnit computeChildMarginValue(const Length& margin);
void computeMainAxisPreferredSizes(OrderHashSet&);
void computeMainAxisPreferredSizes(OrderIterator::OrderValues&);
LayoutUnit adjustChildSizeForMinAndMax(RenderBox&, LayoutUnit childSize);
bool computeNextFlexLine(OrderedFlexItemList& orderedChildren, LayoutUnit& preferredMainAxisExtent, double& totalFlexGrow, double& totalWeightedFlexShrink, LayoutUnit& minMaxAppliedMainAxisExtent, bool& hasInfiniteLineLength);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment