Bug 193058 - clang-tidy: Save 8 padding bytes on WebCore::BorderEdge
Summary: clang-tidy: Save 8 padding bytes on WebCore::BorderEdge
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: David Kilzer (:ddkilzer)
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2018-12-29 16:53 PST by David Kilzer (:ddkilzer)
Modified: 2018-12-30 13:56 PST (History)
6 users (show)

See Also:


Attachments
Patch v1 (2.65 KB, patch)
2018-12-29 16:58 PST, David Kilzer (:ddkilzer)
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description David Kilzer (:ddkilzer) 2018-12-29 16:53:44 PST
Running `clang-tidy -header-filter=.* -checks='-*,clang-analyzer-optin.performance.*' ...` on WebCore source files found unneeded padding bytes in the WebCore::BorderEdge class.

Source/WebCore/rendering/BorderEdge.h:39:7: warning: Excessive padding in 'class WebCore::BorderEdge' (9 padding bytes, where 1 is optimal). 
Optimal fields order: 
m_color, 
m_width, 
m_flooredToDevicePixelWidth, 
m_devicePixelRatio, 
m_style, 
m_isTransparent, 
m_isPresent, 
consider reordering the fields or adding explicit padding members [clang-analyzer-optin.performance.Padding]
class BorderEdge {
      ^
Comment 1 David Kilzer (:ddkilzer) 2018-12-29 16:55:32 PST
$ ./Tools/Scripts/dump-class-layout -c Release -a x86_64 -b $BUILD_DIR WebCore WebCore::BorderEdge
  +0 < 32> BorderEdge
  +0 <  4>     WebCore::LayoutUnit m_width
  +0 <  4>       int m_value
  +4 <  4>   <PADDING: 4 bytes>
  +8 <  8>     WebCore::Color m_color
  +8 <  8>       WebCore::Color::(anonymous union) m_colorData
 +16 <  1>   WebCore::BorderStyle m_style
 +17 <  1>   bool m_isTransparent
 +18 <  1>   bool m_isPresent
 +19 <  1>   <PADDING: 1 byte>
 +20 <  4>   float m_flooredToDevicePixelWidth
 +24 <  4>   float m_devicePixelRatio
 +28 <  4>   <PADDING: 4 bytes>
Total byte size: 32
Total pad bytes: 9
Padding percentage: 28.12 %

Removing 8 padding bytes would make the class 24 bytes.
Comment 2 Radar WebKit Bug Importer 2018-12-29 16:56:20 PST
<rdar://problem/46979275>
Comment 3 David Kilzer (:ddkilzer) 2018-12-29 16:58:54 PST
Created attachment 358141 [details]
Patch v1
Comment 4 David Kilzer (:ddkilzer) 2018-12-29 19:24:05 PST
(In reply to David Kilzer (:ddkilzer) from comment #1)
> $ ./Tools/Scripts/dump-class-layout -c Release -a x86_64 -b $BUILD_DIR
> WebCore WebCore::BorderEdge
>   +0 < 32> BorderEdge
>   +0 <  4>     WebCore::LayoutUnit m_width
>   +0 <  4>       int m_value
>   +4 <  4>   <PADDING: 4 bytes>
>   +8 <  8>     WebCore::Color m_color
>   +8 <  8>       WebCore::Color::(anonymous union) m_colorData
>  +16 <  1>   WebCore::BorderStyle m_style
>  +17 <  1>   bool m_isTransparent
>  +18 <  1>   bool m_isPresent
>  +19 <  1>   <PADDING: 1 byte>
>  +20 <  4>   float m_flooredToDevicePixelWidth
>  +24 <  4>   float m_devicePixelRatio
>  +28 <  4>   <PADDING: 4 bytes>
> Total byte size: 32
> Total pad bytes: 9
> Padding percentage: 28.12 %
> 
> Removing 8 padding bytes would make the class 24 bytes.

After the patch is applied:

$ ./Tools/Scripts/dump-class-layout -c Release -a x86_64 -b $BUILD_DIR WebCore WebCore::BorderEdge
  +0 < 24> BorderEdge
  +0 <  8>     WebCore::Color m_color
  +0 <  8>       WebCore::Color::(anonymous union) m_colorData
  +8 <  4>     WebCore::LayoutUnit m_width
  +8 <  4>       int m_value
 +12 <  4>   float m_flooredToDevicePixelWidth
 +16 <  4>   float m_devicePixelRatio
 +20 <  1>   WebCore::BorderStyle m_style
 +21 <  1>   bool m_isTransparent
 +22 <  1>   bool m_isPresent
 +23 <  1>   <PADDING: 1 byte>
Total byte size: 24
Total pad bytes: 1
Padding percentage: 4.17 %
Comment 5 Yusuke Suzuki 2018-12-30 13:30:17 PST
Comment on attachment 358141 [details]
Patch v1

r=me, nice.
Comment 6 WebKit Commit Bot 2018-12-30 13:56:58 PST
Comment on attachment 358141 [details]
Patch v1

Clearing flags on attachment: 358141

Committed r239563: <https://trac.webkit.org/changeset/239563>
Comment 7 WebKit Commit Bot 2018-12-30 13:56:59 PST
All reviewed patches have been landed.  Closing bug.