Bug 104366 - Make order iterator member stack allocated in RenderFlexibleBox
Summary: Make order iterator member stack allocated in RenderFlexibleBox
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-07 05:48 PST by Carlos Garcia Campos
Modified: 2012-12-20 01:19 PST (History)
7 users (show)

See Also:


Attachments
Patch (25.30 KB, patch)
2012-12-07 05:57 PST, Carlos Garcia Campos
ojan: review-
buildbot: commit-queue-
Details | Formatted Diff | Diff
Updated patch (17.95 KB, patch)
2012-12-18 05:22 PST, Carlos Garcia Campos
tony: review-
Details | Formatted Diff | Diff
Updated patch (16.50 KB, patch)
2012-12-19 00:39 PST, Carlos Garcia Campos
no flags Details | Formatted Diff | Diff
Updated patch to apply on current git master (16.44 KB, patch)
2012-12-19 01:56 PST, Carlos Garcia Campos
tony: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Carlos Garcia Campos 2012-12-07 05:48:55 PST
We avoid heap allocations during layout.
Comment 1 Carlos Garcia Campos 2012-12-07 05:57:20 PST
Created attachment 178209 [details]
Patch
Comment 2 Build Bot 2012-12-07 06:11:52 PST
Comment on attachment 178209 [details]
Patch

Attachment 178209 [details] did not pass win-ews (win):
Output: http://queues.webkit.org/results/15187298
Comment 3 Alexey Proskuryakov 2012-12-07 10:32:08 PST
> We avoid heap allocations during layout.

I'm a layout expert, but this is the first time I hear about this rule. Can you please elaborate?

Will this make RenderFlexibleBox much larger in some cases, or does m_orderIterator always get created eventually anyway?
Comment 4 Alexey Proskuryakov 2012-12-07 10:32:30 PST
> I'm a layout expert,

I'm NOT a layout expert :)
Comment 5 Andreas Kling 2012-12-07 10:37:02 PST
What benchmark (or web page) are you targeting? How big of an improvement is this?
Comment 6 Eric Seidel (no email) 2012-12-07 10:54:02 PST
(In reply to comment #3)
> > We avoid heap allocations during layout.
> 
> I'm a layout expert, but this is the first time I hear about this rule. Can you please elaborate?

We do lots of heap allocations during layout :-)  I haven't read the patch yet. But that rule as stated is overbroad. :-)
Comment 7 Tony Chang 2012-12-07 12:13:00 PST
I don't think Carlos is saying that avoiding heap allocations during layout is a rule.  He's just saying for this code, we'll avoid a heap allocation since we always create this object.  He is simply describing the change.
Comment 8 Ojan Vafai 2012-12-07 12:18:17 PST
Comment on attachment 178209 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=178209&action=review

> Source/WebCore/ChangeLog:14
> +        (WebCore::RenderFlexibleBox::baselinePosition): Make it non const
> +        because the order iterator is modified.

This doesn't work because now it's not actually overriding the parent class's virtual baselinePosition method. constness has to match. I'm not what you should do instead. :(
Comment 9 Tony Chang 2012-12-07 12:21:09 PST
(In reply to comment #8)
> (From update of attachment 178209 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=178209&action=review
> 
> > Source/WebCore/ChangeLog:14
> > +        (WebCore::RenderFlexibleBox::baselinePosition): Make it non const
> > +        because the order iterator is modified.
> 
> This doesn't work because now it's not actually overriding the parent class's virtual baselinePosition method. constness has to match. I'm not what you should do instead. :(

I would probably make m_orderIterator mutable.
Comment 10 Carlos Garcia Campos 2012-12-08 04:55:10 PST
(In reply to comment #7)
> I don't think Carlos is saying that avoiding heap allocations during layout is a rule.  He's just saying for this code, we'll avoid a heap allocation since we always create this object.  He is simply describing the change.

Yes, exactly, the iterator was not a member at first, then it became a member and Tony suggested that maybe we could make it stack allocated, which I think makes sense, so I wrote the patch. This doesn't try to fix a performance issue in the layout algorithm.
Comment 11 Carlos Garcia Campos 2012-12-08 04:55:45 PST
(In reply to comment #8)
> (From update of attachment 178209 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=178209&action=review
> 
> > Source/WebCore/ChangeLog:14
> > +        (WebCore::RenderFlexibleBox::baselinePosition): Make it non const
> > +        because the order iterator is modified.
> 
> This doesn't work because now it's not actually overriding the parent class's virtual baselinePosition method. constness has to match. I'm not what you should do instead. :(

Yes, I noticed it when I saw the windows build failed :-(
Comment 12 Carlos Garcia Campos 2012-12-18 05:22:39 PST
Created attachment 179926 [details]
Updated patch

Make the iterator mutable as suggested by Tony.
Comment 13 Tony Chang 2012-12-18 11:09:38 PST
Comment on attachment 179926 [details]
Updated patch

View in context: https://bugs.webkit.org/attachment.cgi?id=179926&action=review

> Source/WebCore/ChangeLog:8
> +        It avoids heap allocations during the layout.

Nit: I would say, "It avoids a heap allocation during layout."

> Source/WebCore/rendering/RenderFlexibleBox.h:92
> +        void setOrderValues(const OrderHashSet& orderValues)
> +        {
> +            reset();

Can we move this method definition into the .cpp file? That would also let you keep OrderHashTraits in the .cpp file.

> Source/WebCore/rendering/RenderFlexibleBox.h:107
> +        RenderBox* next()
> +        {
> +            do {

Can we move this method definition into the .cpp file?

> Source/WebCore/rendering/RenderFlexibleBox.h:133
> +    private:
> +        RenderFlexibleBox* m_flexibleBox;

Maybe add WTF_MAKE_NONCOPYABLE(OrderIterator) to avoid accidental copies?
Comment 14 Carlos Garcia Campos 2012-12-19 00:39:16 PST
Created attachment 180110 [details]
Updated patch

Moved the implementation of the OrderIterator class to the cpp file and made it non copyable.
Comment 15 Carlos Garcia Campos 2012-12-19 01:56:59 PST
Created attachment 180121 [details]
Updated patch to apply on current git master
Comment 16 Tony Chang 2012-12-19 10:46:57 PST
Comment on attachment 180121 [details]
Updated patch to apply on current git master

Thanks!
Comment 17 Carlos Garcia Campos 2012-12-20 01:19:23 PST
Committed r138235: <http://trac.webkit.org/changeset/138235>