Bug 105065 - Free one bit in RenderObject
Summary: Free one bit in RenderObject
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Julien Chaffraix
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-14 16:03 PST by Julien Chaffraix
Modified: 2012-12-18 21:21 PST (History)
5 users (show)

See Also:


Attachments
Proposed stealing: Pack the positioned bits more efficiently to save one bit. (13.02 KB, patch)
2012-12-14 16:43 PST, Julien Chaffraix
no flags Details | Formatted Diff | Diff
Updated fix: added the comment ojan's requested. (13.08 KB, patch)
2012-12-18 09:38 PST, Julien Chaffraix
no flags Details | Formatted Diff | Diff
Patch for landing (13.13 KB, patch)
2012-12-18 16:19 PST, Julien Chaffraix
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Julien Chaffraix 2012-12-14 16:03:25 PST
In order to implement bug 104829, I need to steal a bit on RenderObject as the class is completely packed.
Comment 1 Simon Fraser (smfr) 2012-12-14 16:36:27 PST
Get rid of the 'being dragged' bit.
Comment 2 Simon Fraser (smfr) 2012-12-14 16:37:36 PST
We we really want to waste a bit for this? I think a bit would be put to more use for something like bug 102617. Seems like it would be better to track things that need pre-layout via some side-band mechanism.
Comment 3 Julien Chaffraix 2012-12-14 16:43:41 PST
Created attachment 179555 [details]
Proposed stealing: Pack the positioned bits more efficiently to save one bit.
Comment 4 Julien Chaffraix 2012-12-14 16:54:30 PST
Simon, I didn't see your comments and already have made some efforts around free'ing one bit (that doesn't mean we *have* to use it for bug 104829).

> We we really want to waste a bit for this? I think a bit would be put to more use for something like bug 102617. Seems like it would be better to track things that need pre-layout via some side-band mechanism.

Not sure about the out-of-band mechanism, we are going with a tree traversal so that means we will have to do some hash lookup for each renderer which could end up being expensive.

> Get rid of the 'being dragged' bit.

AFAICT the 'being dragged bit' applies to a subtree so I am not 100% sure it can be removed easily. Another candidate was the reflection bit but we would need some data (it feels rare). I went for a free bit.
Comment 5 Ojan Vafai 2012-12-14 18:02:34 PST
Comment on attachment 179555 [details]
Proposed stealing: Pack the positioned bits more efficiently to save one bit.

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

> Source/WebCore/rendering/RenderObject.h:1122
> +        void setPositionedState(int positionState) { m_positionedState = static_cast<PositionedState>(positionState & 0x3); }

This deserves a comment that we are doing this to save a bit by mapping AbsolutePosition and FixedPosition to the same state.
Comment 6 Simon Fraser (smfr) 2012-12-15 09:03:31 PST
Comment on attachment 179555 [details]
Proposed stealing: Pack the positioned bits more efficiently to save one bit.

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

> Source/WebCore/rendering/style/RenderStyleConstants.h:102
> +    StaticPosition = 0,
> +    RelativePosition = 1,
> +    AbsolutePosition = 2,
> +    /* Required to pack our bits efficiently in RenderObject. */
> +    FixedPosition = 6,
> +    StickyPosition = 3

This ordering is confusing. Why not put StickyPosition in order? It would be clearer why you're using 6 for FixedPosition if you declared this with bits:

const unsigned InFlowPositionBit = 0
const unsigned OutOfFlowPositionBit = 1

FixedPosition = 1 << 2 | 1 <<  OutOfFlowPositionBit
or something.
We could also add isInFlowPositioned() const { return foo & (1 << InFlowPositionBit) } at some point.
Comment 7 Julien Chaffraix 2012-12-17 14:24:33 PST
Comment on attachment 179555 [details]
Proposed stealing: Pack the positioned bits more efficiently to save one bit.

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

>> Source/WebCore/rendering/RenderObject.h:1122
>> +        void setPositionedState(int positionState) { m_positionedState = static_cast<PositionedState>(positionState & 0x3); }
> 
> This deserves a comment that we are doing this to save a bit by mapping AbsolutePosition and FixedPosition to the same state.

Sounds good.

>> Source/WebCore/rendering/style/RenderStyleConstants.h:102
>> +    StickyPosition = 3
> 
> This ordering is confusing. Why not put StickyPosition in order? It would be clearer why you're using 6 for FixedPosition if you declared this with bits:
> 
> const unsigned InFlowPositionBit = 0
> const unsigned OutOfFlowPositionBit = 1
> 
> FixedPosition = 1 << 2 | 1 <<  OutOfFlowPositionBit
> or something.
> We could also add isInFlowPositioned() const { return foo & (1 << InFlowPositionBit) } at some point.

First, OK for the ordering.

It would be possible to do what you propose but there is a big downside. However screwy this code looks like, it makes it very efficient to convert from EPosition to PositionedState and what makes this possible is that AbsolutePosition and FixedPosition have the same lower bits but differ on the high bit, which we mask out.

With your scheme, I can't think of a way that wouldn't include a branch (there may be a way with some pretty crazy bit arithmetic).
Comment 8 Simon Fraser (smfr) 2012-12-17 14:55:19 PST
(In reply to comment #7)
> >> Source/WebCore/rendering/style/RenderStyleConstants.h:102
> >> +    StickyPosition = 3
> > 
> > This ordering is confusing. Why not put StickyPosition in order? It would be clearer why you're using 6 for FixedPosition if you declared this with bits:
> > 
> > const unsigned InFlowPositionBit = 0
> > const unsigned OutOfFlowPositionBit = 1
> > 
> > FixedPosition = 1 << 2 | 1 <<  OutOfFlowPositionBit
> > or something.
> > We could also add isInFlowPositioned() const { return foo & (1 << InFlowPositionBit) } at some point.
> 
> First, OK for the ordering.
> 
> It would be possible to do what you propose but there is a big downside. However screwy this code looks like, it makes it very efficient to convert from EPosition to PositionedState and what makes this possible is that AbsolutePosition and FixedPosition have the same lower bits but differ on the high bit, which we mask out.
> 
> With your scheme, I can't think of a way that wouldn't include a branch (there may be a way with some pretty crazy bit arithmetic).

 My scheme has the same bit layout as your scheme, unless I was misunderstanding. I was just asking for your scheme's bit layout to be more explicit in the code.
Comment 9 Julien Chaffraix 2012-12-17 15:22:43 PST
> > With your scheme, I can't think of a way that wouldn't include a branch (there may be a way with some pretty crazy bit arithmetic).
> 
>  My scheme has the same bit layout as your scheme, unless I was misunderstanding. I was just asking for your scheme's bit layout to be more explicit in the code.

Now you got me confused, not about the goal but the proposal in comment #6: 

const unsigned OutOfFlowPositionBit = 1

FixedPosition = 1 << 2 | 1 <<  OutOfFlowPositionBit

As defined the bit is set on both AbsolutePosition and FixedPosition but also on StickyPosition (= 3), which makes the name confusing. If you change StickPosition value to hold having an OutOfFlowPositionBit is where it adds more conversion complexity.
Comment 10 Simon Fraser (smfr) 2012-12-17 15:46:10 PST
I got my bits wrong, sorry.
Comment 11 Julien Chaffraix 2012-12-17 16:57:49 PST
Thanks Simon, I wanted to make sure I wasn't missing something obvious. Re-titling the bug as we will use an out-of-band mechanism for bug 104829 and see how this goes. We can always change our mind later if we find some performance bottleneck.
Comment 12 Julien Chaffraix 2012-12-18 09:38:42 PST
Created attachment 179962 [details]
Updated fix: added the comment ojan's requested.
Comment 13 Julien Chaffraix 2012-12-18 16:19:25 PST
Comment on attachment 179962 [details]
Updated fix: added the comment ojan's requested.

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

> Source/WebCore/rendering/style/RenderStyleConstants.h:101
> +    /* This value is required to pack our bits efficiently in RenderObject. */

This C style comment slipped in, I will fix before landing.
Comment 14 Julien Chaffraix 2012-12-18 16:19:49 PST
Created attachment 180051 [details]
Patch for landing
Comment 15 WebKit Review Bot 2012-12-18 21:20:59 PST
Comment on attachment 180051 [details]
Patch for landing

Clearing flags on attachment: 180051

Committed r138113: <http://trac.webkit.org/changeset/138113>
Comment 16 WebKit Review Bot 2012-12-18 21:21:03 PST
All reviewed patches have been landed.  Closing bug.