RESOLVED FIXED118620
Use a Vector instead of HashSet to compute the orderValues in RenderFlexibleBox
https://bugs.webkit.org/show_bug.cgi?id=118620
Summary Use a Vector instead of HashSet to compute the orderValues in RenderFlexibleBox
Ryosuke Niwa
Reported 2013-07-12 14:58:00 PDT
We should probably merge https://chromium.googlesource.com/chromium/blink/+/f8d1285399d9e1ee079e2babf4fd8c6f337855d7 Also, special-case the very much common case of only having the default order value of 0. This accounts for ~1% of the profile on flexbox-lots-of-data.html from crbug.com/249986. Order is extremely uncommon. If there turn out to be sites that use a large number of different order values, then we have to rethink how we store this data (i.e. right now we loop over all the flex items for each order value).
Attachments
Patch (119.54 KB, patch)
2013-10-14 04:34 PDT, Sergio Villar Senin
no flags
Patch (119.31 KB, patch)
2013-10-21 03:57 PDT, Sergio Villar Senin
no flags
Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 (440.55 KB, application/zip)
2013-10-21 04:46 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-05 for mac-mountainlion (473.52 KB, application/zip)
2013-10-21 05:05 PDT, Build Bot
no flags
Patch (119.04 KB, patch)
2013-10-22 04:17 PDT, Sergio Villar Senin
no flags
Archive of layout-test-results from webkit-ews-04 for mac-mountainlion (646.49 KB, application/zip)
2013-10-22 04:48 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-12 for mac-mountainlion-wk2 (515.63 KB, application/zip)
2013-10-22 05:08 PDT, Build Bot
no flags
Patch (119.14 KB, patch)
2013-10-22 08:24 PDT, Sergio Villar Senin
no flags
Archive of layout-test-results from webkit-ews-14 for mac-mountainlion-wk2 (437.16 KB, application/zip)
2013-10-22 09:06 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-07 for mac-mountainlion (477.40 KB, application/zip)
2013-10-22 09:40 PDT, Build Bot
no flags
Archive of layout-test-results from webkit-ews-01 for mac-mountainlion (481.75 KB, application/zip)
2013-10-22 10:40 PDT, Build Bot
no flags
Patch (118.90 KB, patch)
2013-10-23 04:22 PDT, Sergio Villar Senin
no flags
Rebased. Including Antti's suggestions (118.88 KB, patch)
2013-10-23 07:59 PDT, Sergio Villar Senin
no flags
Patch (118.82 KB, patch)
2013-10-25 02:38 PDT, Sergio Villar Senin
no flags
Sergio Villar Senin
Comment 1 2013-10-14 04:34:59 PDT
Antti Koivisto
Comment 2 2013-10-14 04:49:17 PDT
Comment on attachment 214143 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=214143&action=review r=me with these fixes. > Source/WebCore/rendering/RenderFlexibleBox.cpp:59 > + std::sort(orderValues.begin(), orderValues.end()); > + > + Please remove the extra empty line. > Source/WebCore/rendering/RenderFlexibleBox.cpp:64 > + // This is inefficient if there are many repeated values, but > + // saves a lot of allocations when the values are unique. By far, > + // the common case is that there's exactly one item in the list > + // (the default order value of 0). > + m_orderValues.reserveInitialCapacity(orderValues.size()); The comment is overly long and adds little value. > Source/WebCore/rendering/RenderFlexibleBox.cpp:74 > + int previous = orderValues[0]; > + m_orderValues.append(previous); > + for (size_t i = 1; i < orderValues.size(); ++i) { > + int current = orderValues[i]; > + if (current == previous) > + continue; > + m_orderValues.append(current); > + previous = current; > + } Please get rid of the current and previous variables and just use orderValues[i], orderValues[i-1]
Antti Koivisto
Comment 3 2013-10-14 04:55:46 PDT
Comment on attachment 214143 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=214143&action=review > Source/WebCore/rendering/RenderFlexibleBox.cpp:957 > + if (anyChildHasDefaultOrderValue) { > + // Avoid growing the vector to the default capacity of 16 if we're only going to put one item in it. > + if (orderValues.isEmpty()) > + orderValues.reserveInitialCapacity(1); > + orderValues.append(0); > + } I think we can just use Vector<int, 1> instead of this clumsy optimisation.
Antti Koivisto
Comment 4 2013-10-14 04:57:02 PDT
Comment on attachment 214143 [details] Patch There is quite a bit to change really so lets get another patch.
Andreas Kling
Comment 5 2013-10-14 04:58:26 PDT
Comment on attachment 214143 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=214143&action=review > Source/WebCore/rendering/RenderFlexibleBox.cpp:72 > + m_orderValues.append(current); You can use uncheckedAppend() here since you know that there will always be space for {orderValues.size()} elements.
Antti Koivisto
Comment 6 2013-10-14 05:04:09 PDT
Comment on attachment 214143 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=214143&action=review >> Source/WebCore/rendering/RenderFlexibleBox.cpp:74 >> + int previous = orderValues[0]; >> + m_orderValues.append(previous); >> + for (size_t i = 1; i < orderValues.size(); ++i) { >> + int current = orderValues[i]; >> + if (current == previous) >> + continue; >> + m_orderValues.append(current); >> + previous = current; >> + } > > Please get rid of the current and previous variables and just use orderValues[i], orderValues[i-1] The whole loop can probably be replaced by a call to std::unique.
Sergio Villar Senin
Comment 7 2013-10-14 09:57:18 PDT
Antti what if instead of replacing it with a Vector<int, 1> which has to be orderer and stuff, we use a std::set ?
Antti Koivisto
Comment 8 2013-10-14 11:16:23 PDT
We don't currently use STL containers in WebKit, only algorithms. Whether we should is outside scope of this bug.
Sergio Villar Senin
Comment 9 2013-10-21 03:57:20 PDT
Sergio Villar Senin
Comment 10 2013-10-21 04:00:34 PDT
The thing I don't like about my patch is that I'm removing the constness of the argument to the set() function just to try to minimize the amount of copies. If our assumption that the most common case is just a few order values is correct then I guess I should change it (we are copying all the values in any case with the current code).
Build Bot
Comment 11 2013-10-21 04:46:50 PDT
Comment on attachment 214723 [details] Patch Attachment 214723 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/8868001 New failing tests: mathml/presentation/scripts-horizontal-alignment.html
Build Bot
Comment 12 2013-10-21 04:46:52 PDT
Created attachment 214726 [details] Archive of layout-test-results from webkit-ews-09 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-09 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Build Bot
Comment 13 2013-10-21 05:05:42 PDT
Comment on attachment 214723 [details] Patch Attachment 214723 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/8758006 New failing tests: mathml/presentation/scripts-horizontal-alignment.html
Build Bot
Comment 14 2013-10-21 05:05:46 PDT
Created attachment 214728 [details] Archive of layout-test-results from webkit-ews-05 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-05 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Antti Koivisto
Comment 15 2013-10-21 10:06:11 PDT
Comment on attachment 214723 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=214723&action=review > Source/WebCore/rendering/RenderFlexibleBox.cpp:941 > + if (anyChildHasDefaultOrderValue) > + orderValues.append(0); You don't need anyChildHasDefaultOrderValue boolean. You can just do If (orderValue.isEmpty() && firstChildBox())
Sergio Villar Senin
Comment 16 2013-10-22 04:17:51 PDT
Build Bot
Comment 17 2013-10-22 04:48:22 PDT
Comment on attachment 214836 [details] Patch Attachment 214836 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/8818257 New failing tests: mathml/presentation/scripts-horizontal-alignment.html mathml/presentation/multiscript-subscriptshift.html platform/mac/accessibility/mathml-elements.html mathml/presentation/multiscript-superscriptshift.html mathml/presentation/multiscripts-positions.html mathml/presentation/scripts-underover.html platform/mac/accessibility/mathml-multiscript.html css3/flexbox/style-change.html
Build Bot
Comment 18 2013-10-22 04:48:25 PDT
Created attachment 214838 [details] Archive of layout-test-results from webkit-ews-04 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-04 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Build Bot
Comment 19 2013-10-22 05:08:16 PDT
Comment on attachment 214836 [details] Patch Attachment 214836 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/8848278 New failing tests: mathml/presentation/scripts-horizontal-alignment.html mathml/presentation/multiscript-subscriptshift.html platform/mac/accessibility/mathml-elements.html mathml/presentation/multiscript-superscriptshift.html mathml/presentation/multiscripts-positions.html mathml/presentation/scripts-underover.html platform/mac/accessibility/mathml-multiscript.html css3/flexbox/style-change.html
Build Bot
Comment 20 2013-10-22 05:08:19 PDT
Created attachment 214840 [details] Archive of layout-test-results from webkit-ews-12 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-12 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Sergio Villar Senin
Comment 21 2013-10-22 08:05:12 PDT
(In reply to comment #15) > (From update of attachment 214723 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=214723&action=review > > > Source/WebCore/rendering/RenderFlexibleBox.cpp:941 > > + if (anyChildHasDefaultOrderValue) > > + orderValues.append(0); > > You don't need anyChildHasDefaultOrderValue boolean. You can just do > > If (orderValue.isEmpty() && firstChildBox()) Actually we can't do this because we never append 0 inside the loop (as it's the most common value). We need to know not only if there is some child but also if any of them is actually 0.
Sergio Villar Senin
Comment 22 2013-10-22 08:24:35 PDT
Antti Koivisto
Comment 23 2013-10-22 08:52:15 PDT
> > If (orderValue.isEmpty() && firstChildBox()) > > Actually we can't do this because we never append 0 inside the loop (as it's the most common value). We need to know not only if there is some child but also if any of them is actually 0. I know. I'm just saying you don't need the boolean. (the above should say orderValues.isEmpty())
Build Bot
Comment 24 2013-10-22 09:06:49 PDT
Comment on attachment 214859 [details] Patch Attachment 214859 [details] did not pass mac-wk2-ews (mac-wk2): Output: http://webkit-queues.appspot.com/results/8888352 New failing tests: mathml/presentation/scripts-horizontal-alignment.html
Build Bot
Comment 25 2013-10-22 09:06:52 PDT
Created attachment 214861 [details] Archive of layout-test-results from webkit-ews-14 for mac-mountainlion-wk2 The attached test failures were seen while running run-webkit-tests on the mac-wk2-ews. Bot: webkit-ews-14 Port: mac-mountainlion-wk2 Platform: Mac OS X 10.8.5
Build Bot
Comment 26 2013-10-22 09:40:48 PDT
Comment on attachment 214859 [details] Patch Attachment 214859 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/8908313 New failing tests: mathml/presentation/scripts-horizontal-alignment.html
Build Bot
Comment 27 2013-10-22 09:40:52 PDT
Created attachment 214865 [details] Archive of layout-test-results from webkit-ews-07 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-07 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Build Bot
Comment 28 2013-10-22 10:40:21 PDT
Comment on attachment 214859 [details] Patch Attachment 214859 [details] did not pass mac-ews (mac): Output: http://webkit-queues.appspot.com/results/8878366 New failing tests: mathml/presentation/scripts-horizontal-alignment.html
Build Bot
Comment 29 2013-10-22 10:40:24 PDT
Created attachment 214870 [details] Archive of layout-test-results from webkit-ews-01 for mac-mountainlion The attached test failures were seen while running run-webkit-tests on the mac-ews. Bot: webkit-ews-01 Port: mac-mountainlion Platform: Mac OS X 10.8.5
Sergio Villar Senin
Comment 30 2013-10-23 04:22:55 PDT
Sergio Villar Senin
Comment 31 2013-10-23 07:59:19 PDT
Created attachment 214962 [details] Rebased. Including Antti's suggestions
Antti Koivisto
Comment 32 2013-10-23 11:48:04 PDT
Comment on attachment 214962 [details] Rebased. Including Antti's suggestions r=me
Sergio Villar Senin
Comment 33 2013-10-23 23:52:04 PDT
Alexey Proskuryakov
Comment 34 2013-10-24 09:29:35 PDT
This broke perfbot, so I'm going to roll out in a moment. There are no diffs, but search for Layout/flexbox-lots-of-data.html in <http://build.webkit.org/builders/Apple%20MountainLion%20Release%20%28Perf%29/builds/6878/steps/perf-test/logs/stdio>
WebKit Commit Bot
Comment 35 2013-10-24 09:31:12 PDT
Re-opened since this is blocked by bug 123274
Antti Koivisto
Comment 36 2013-10-24 09:45:47 PDT
Maybe that hash was needed after all! The correct data structure here might really be a heap.
Sergio Villar Senin
Comment 37 2013-10-24 09:58:36 PDT
(In reply to comment #36) > Maybe that hash was needed after all! Let's see first why the test was not running :) The change didn't break any test actually, because as I told ap, the test was added by this change.
Sergio Villar Senin
Comment 38 2013-10-25 02:38:24 PDT
Created attachment 215156 [details] Patch The problem was the test itself that was generating some output confusing the testing tool
Sergio Villar Senin
Comment 39 2013-10-25 03:30:23 PDT
Comment on attachment 215156 [details] Patch Clearing flags on attachment: 215156 Committed r157999: <http://trac.webkit.org/changeset/157999>
Sergio Villar Senin
Comment 40 2013-10-25 03:30:32 PDT
All reviewed patches have been landed. Closing bug.
Darin Adler
Comment 41 2013-10-25 12:52:56 PDT
Comment on attachment 215156 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=215156&action=review > Source/WebCore/rendering/RenderFlexibleBox.h:82 > + void setOrderValues(const OrderValues&); This seems like a good place to use move semantics so we don’t have to allocate a new vector. Can we have this take OrderValues&& instead and use std::move?
Sergio Villar Senin
Comment 42 2013-10-28 00:19:19 PDT
(In reply to comment #41) > (From update of attachment 215156 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=215156&action=review > > > Source/WebCore/rendering/RenderFlexibleBox.h:82 > > + void setOrderValues(const OrderValues&); > > This seems like a good place to use move semantics so we don’t have to allocate a new vector. Can we have this take OrderValues&& instead and use std::move? Sure, I'll change it before landing.
Sergio Villar Senin
Comment 43 2013-10-28 02:30:32 PDT
(In reply to comment #42) > (In reply to comment #41) > > (From update of attachment 215156 [details] [details]) > > View in context: https://bugs.webkit.org/attachment.cgi?id=215156&action=review > > > > > Source/WebCore/rendering/RenderFlexibleBox.h:82 > > > + void setOrderValues(const OrderValues&); > > > > This seems like a good place to use move semantics so we don’t have to allocate a new vector. Can we have this take OrderValues&& instead and use std::move? > > Sure, I'll change it before landing. I meant, in a follow up patch because it landed on friday
Note You need to log in before you can comment on or make changes to this bug.