Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 03a3ba478957e0cf3ab13cbc0e031be092ce32fc
      
https://github.com/WebKit/WebKit/commit/03a3ba478957e0cf3ab13cbc0e031be092ce32fc
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-08-20 (Thu, 20 Aug 2026)

  Changed paths:
    M Source/WebCore/html/canvas/CanvasDirection.h
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp
    M Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h
    M Source/WebCore/platform/graphics/GraphicsTypes.h

  Log Message:
  -----------
  [Canvas] Reorder CanvasRenderingContext2DBase::State to remove 24 bytes of 
padding
https://bugs.webkit.org/show_bug.cgi?id=322158
rdar://185384284

Reviewed by Chris Dumez.

State is copied by value on every save() (realizeSavesLoop) and stored in a
Vector<State, 1>, but its fields interleave 1-byte enums with doubles and leave
18 bytes of padding: 6 bytes after lineCap/lineJoin, 4 after shadowBlur, 6
after globalComposite/globalBlend, and 2 after imageSmoothingQuality.

Group the sub-word fields into a single trailing block and give TextAlign,
TextBaseline and CanvasDirection an explicit uint8_t underlying type, matching
the rest of the canvas enums. TextAlign and TextBaseline are unscoped enums
used only by canvas 2D, so they were 4 bytes each for five and six enumerators.

sizeof(State) goes from 824 to 800 bytes, verified identical for both ABIs --
arm64-apple-macos and x86_64-pc-windows-msvc -- with -Xclang
-fdump-record-layouts-complete. Every field in the padded regions is a double,
float, bool, Color, FloatSize or fixed-underlying-type enum, and State has no
base classes or bitfields, so the Itanium and MSVC layouts agree field for
field. The inline capacity of m_stateStack means every 2D context object
shrinks by the same 24 bytes, and a save() at maximum depth (MaxSaveCount is
16384) allocates 384 KB less (extreme case).

No change in behavior.

* Source/WebCore/html/canvas/CanvasDirection.h:
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:
(WebCore::CanvasRenderingContext2DBase::State::State):
* Source/WebCore/html/canvas/CanvasRenderingContext2DBase.h:
* Source/WebCore/platform/graphics/GraphicsTypes.h:

Canonical link: https://commits.webkit.org/319513@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to