RESOLVED FIXED 188713
Pack booleans in Event into a bitfield
https://bugs.webkit.org/show_bug.cgi?id=188713
Summary Pack booleans in Event into a bitfield
Ryosuke Niwa
Reported 2018-08-17 17:31:16 PDT
Make Event object slightly smaller.
Attachments
Cleanup (5.42 KB, patch)
2018-08-17 17:41 PDT, Ryosuke Niwa
dbates: review+
Ryosuke Niwa
Comment 1 2018-08-17 17:41:30 PDT
EWS Watchlist
Comment 2 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.
Daniel Bates
Comment 3 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.
Simon Fraser (smfr)
Comment 4 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.
Ryosuke Niwa
Comment 5 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.
Ryosuke Niwa
Comment 6 2018-08-17 23:47:24 PDT
Radar WebKit Bug Importer
Comment 7 2018-08-17 23:48:23 PDT
Yusuke Suzuki
Comment 8 2018-08-19 01:06:27 PDT
Nice!
Lucas Forschler
Comment 9 2019-02-06 09:19:08 PST
Mass move bugs into the DOM component.
Note You need to log in before you can comment on or make changes to this bug.