RESOLVED FIXED 65783
refactor box-ordinal-group handling so we don't timeout on large values
https://bugs.webkit.org/show_bug.cgi?id=65783
Summary refactor box-ordinal-group handling so we don't timeout on large values
Tony Chang
Reported 2011-08-05 12:11:53 PDT
refactor box-ordinal-group handling so we don't timeout on large values
Attachments
Patch (7.92 KB, patch)
2011-08-05 12:15 PDT, Tony Chang
no flags
Patch (7.85 KB, patch)
2011-08-05 13:19 PDT, Tony Chang
no flags
Patch (7.77 KB, patch)
2011-08-09 13:17 PDT, Tony Chang
no flags
Patch (8.71 KB, patch)
2011-08-30 13:23 PDT, Tony Chang
hyatt: review+
Tony Chang
Comment 1 2011-08-05 12:15:04 PDT
Early Warning System Bot
Comment 2 2011-08-05 12:24:22 PDT
Gyuyoung Kim
Comment 3 2011-08-05 12:28:25 PDT
WebKit Review Bot
Comment 4 2011-08-05 12:34:53 PDT
Gustavo Noronha (kov)
Comment 5 2011-08-05 12:46:08 PDT
Tony Chang
Comment 6 2011-08-05 13:19:16 PDT
Dave Hyatt
Comment 7 2011-08-08 12:50:19 PDT
Comment on attachment 103099 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=103099&action=review This is just way too slow. You'll sort all the kids every time you do a layout. Keep in mind that flex-order is rarely ever going to be used. A couple of ideas: (1) Instead of caching only m_lastOrdinal, cache all the specified ordinals as you encounter them when walking. Just make a little inthash. PROS: Can just do a normal RenderObject walk when box-ordinal-group is 1. CONS: Do one complete walk of the entire list for each value of box-ordinal-group. PERFORMANCE: O(n*m) where n is the # of children and m is the number of unique box-ordinal-group values. MEMORY: O(m) where m is the number of unique box-ordinal-group values stored in the IntHash. (2) Start off walking the children and only if you encounter a box-ordinal-group value of 1 do you fault to being sorted. PROS: Will perform better with box-ordinal-group values other than just 1. CONS: Takes up a lot of extra memory when you only have a couple of box-ordinal-group values (probably the common case). PERFORMANCE: O(n) where n is the # of children. MEMORY: O(n) where n is the number of children. (3) Same as (2) but instead of a single sorted Vector, make an IntHash of (box-ordinal-group) -> Vectors. PROS: Easy to look only at a specific group. CONS: Takes up a lot of extra memory still when you only have a couple of box-ordinal-group values. PERFORMANCE: O(n) where n is the number of children. MEMORY: O(n) where n is the number of children. Given the characteristics of flex-order, I'm inclined to favor approach #1. I don't think doing multiple walks of the child list will be that big a deal. > Source/WebCore/ChangeLog:10 > + vector and sorts them. If box-oridinal-group is all the default Typo. "ordinal" > Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp:85 > + static bool compareFlexOrder(RenderBox* r1, RenderBox* r2) > + { > + return r1->style()->boxOrdinalGroup() < r2->style()->boxOrdinalGroup(); > + } I don't think compareFlexOrder is the right term. box-ordinal-group is about re-ordering the items. I'd just call the function compare() :).
Dave Hyatt
Comment 8 2011-08-08 12:52:55 PDT
Some clarifications. For approach (1) you could use an IntHashSet rather than a map. For approach (3) you could probably special case box-ordinal-group of 1 to just walk the normal child list and to not actually store a sorted Vector, i.e., only hold sorted child lists for the other box-ordinal-groups. It seems to me that - given the rarity of this feature - approach #1 is the easiest.
Tony Chang
Comment 9 2011-08-08 15:53:38 PDT
I tried to implement approach (1), but HashSet is not sorted, so once we collect the ordinals, we need to manually copy to a Vector and sort it. The main downside to this approach is the extra memory it uses. Really what I want is an STL set, but the closest thing I see to that is AVLTree.h. Perhaps I should just use the AVL tree and before inserting, check to see if the value I'm inserting already exists or not. Maybe Darin has some data structure advice.
Tony Chang
Comment 10 2011-08-09 13:17:21 PDT
Tony Chang
Comment 11 2011-08-09 13:22:33 PDT
I went with (1) and copy to a vector and sort. AVLTree seemed like a lot of code weight for this edge case (it doesn't appear to be used anywhere except leveldb). There's also WebCore/platform/PODRedBlackTree, but it would require some modifications to get the max value and if we wanted to make inserts cheap.
Ojan Vafai
Comment 12 2011-08-29 16:28:49 PDT
Comment on attachment 103387 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=103387&action=review Code and test looks good to me. Would be good to get at least a high-level OK from Hyatt though. > Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp:28 > +#include "PODRedBlackTree.h" I think you meant to delete this. > Source/WebCore/rendering/RenderDeprecatedFlexibleBox.cpp:85 > + if (static_cast<size_t>(m_ordinalValues.size()) != m_sortedOrdinalValues.size()) { Maybe add a comment saying why we do this size check? Namely, that it avoids regenerating and sorting m_sortedOrdinalValues when the iterator is reset, which happens frequently.
Tony Chang
Comment 13 2011-08-30 13:23:53 PDT
Dave Hyatt
Comment 14 2011-08-30 13:36:37 PDT
Comment on attachment 105682 [details] Patch r=me
Tony Chang
Comment 15 2011-08-30 13:52:47 PDT
Note You need to log in before you can comment on or make changes to this bug.