Bug 188713 - Pack booleans in Event into a bitfield
Summary: Pack booleans in Event into a bitfield
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-08-17 17:31 PDT by Ryosuke Niwa
Modified: 2019-02-06 09:19 PST (History)
9 users (show)

See Also:


Attachments
Cleanup (5.42 KB, patch)
2018-08-17 17:41 PDT, Ryosuke Niwa
dbates: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ryosuke Niwa 2018-08-17 17:31:16 PDT
Make Event object slightly smaller.
Comment 1 Ryosuke Niwa 2018-08-17 17:41:30 PDT
Created attachment 347419 [details]
Cleanup
Comment 2 EWS Watchlist 2018-08-17 17:44:47 PDT
Attachment 347419 [details] did not pass style-queue:


ERROR: Source/WebCore/dom/Event.cpp:39:  Code inside a namespace should not be indented.  [whitespace/indent] [4]
Total errors found: 1 in 3 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 Daniel Bates 2018-08-17 18:20:50 PDT
Comment on attachment 347419 [details]
Cleanup

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

> Source/WebCore/dom/Event.cpp:37
> +ALWAYS_INLINE Event::Event(MonotonicTime createTime, const AtomicString& type, IsTrusted isTrusted, CanBubble canBubble, IsCancelable cancelable, IsComposed composed)

This feels like a step backwards from using default initializers. I am assuming it is a memory footprint win. Once we move to C++20 we can use default initalizers for bitfields.

> Source/WebCore/dom/Event.h:171
> +    unsigned m_eventPhase : 2; // 13-bits

I wish we had a good solution for this. Very easy for a person to add a new every phase and forget to update the width (if needed). This problem is not unique to this code. One tactic I have seen is to define a constexpr for the width above the enum in the hope that a person sees it. Another tactic is to add placeholder enum after last enumerator then compute width.
Comment 4 Simon Fraser (smfr) 2018-08-17 19:15:08 PDT
Comment on attachment 347419 [details]
Cleanup

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

>> Source/WebCore/dom/Event.h:171
>> +    unsigned m_eventPhase : 2; // 13-bits
> 
> I wish we had a good solution for this. Very easy for a person to add a new every phase and forget to update the width (if needed). This problem is not unique to this code. One tactic I have seen is to define a constexpr for the width above the enum in the hope that a person sees it. Another tactic is to add placeholder enum after last enumerator then compute width.

It took me a few seconds to realize that the "13 bits" didn't mean that m_eventPhase needs 13 bits. I think this comment is confusing, and dump-class-layout can show bit counts so there's no need for the comment now.
Comment 5 Ryosuke Niwa 2018-08-17 23:44:19 PDT
(In reply to Daniel Bates from comment #3)
> Comment on attachment 347419 [details]
> Cleanup
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=347419&action=review
> 
> > Source/WebCore/dom/Event.cpp:37
> > +ALWAYS_INLINE Event::Event(MonotonicTime createTime, const AtomicString& type, IsTrusted isTrusted, CanBubble canBubble, IsCancelable cancelable, IsComposed composed)
> 
> This feels like a step backwards from using default initializers. I am
> assuming it is a memory footprint win. Once we move to C++20 we can use
> default initalizers for bitfields.

Yeah, it would be nice to be able to use default initializers with bitfields.

(In reply to Simon Fraser (smfr) from comment #4)
> Comment on attachment 347419 [details]
> Cleanup
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=347419&action=review
> 
> >> Source/WebCore/dom/Event.h:171
> >> +    unsigned m_eventPhase : 2; // 13-bits
> > 
> > I wish we had a good solution for this. Very easy for a person to add a new every phase and forget to update the width (if needed). This problem is not unique to this code. One tactic I have seen is to define a constexpr for the width above the enum in the hope that a person sees it. Another tactic is to add placeholder enum after last enumerator then compute width.
> 
> It took me a few seconds to realize that the "13 bits" didn't mean that
> m_eventPhase needs 13 bits. I think this comment is confusing, and
> dump-class-layout can show bit counts so there's no need for the comment now.

Okay, will remove the comment.
Comment 6 Ryosuke Niwa 2018-08-17 23:47:24 PDT
Committed r235009: <https://trac.webkit.org/changeset/235009>
Comment 7 Radar WebKit Bug Importer 2018-08-17 23:48:23 PDT
<rdar://problem/43454338>
Comment 8 Yusuke Suzuki 2018-08-19 01:06:27 PDT
Nice!
Comment 9 Lucas Forschler 2019-02-06 09:19:08 PST
Mass move bugs into the DOM component.