Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 2c0cc9251bcd4e0e897f8d4c24fe9582a8410544
      
https://github.com/WebKit/WebKit/commit/2c0cc9251bcd4e0e897f8d4c24fe9582a8410544
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-08-05 (Wed, 05 Aug 2026)

  Changed paths:
    M Source/WebCore/Modules/webaudio/AudioNode.cpp
    M Source/WebCore/Modules/webaudio/AudioNode.h
    M Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp
    M Source/WebCore/Modules/webaudio/AudioParamTimeline.h
    M Source/WebCore/Modules/webaudio/RealtimeAnalyser.h

  Log Message:
  -----------
  [Web Audio] Reduce padding in ParamEvent, AutomationState, AudioNode and 
RealtimeAnalyser
https://bugs.webkit.org/show_bug.cgi?id=321106
rdar://184144764

Reviewed by Chris Dumez.

Several Web Audio classes interleave 8-byte and 4-byte members, leaving interior
and trailing holes. Group members by alignment to close them. Sizes measured 
with
-fdump-record-layouts using WebCore's Release compile flags (arm64e):

AudioParamTimeline::ParamEvent88 -> 80
AudioParamTimeline::AutomationState112 -> 104
AudioNode160 -> 152
RealtimeAnalyser 120 -> 112

* Source/WebCore/Modules/webaudio/AudioParamTimeline.h:
(WebCore::AudioParamTimeline::ParamEvent::ParamEvent):
Move the Seconds/Vector/double/optional members ahead of the floats. Reordering
alone saves nothing here (the payload lands at 81 bytes and still rounds to 88),
so ParamEvent::Type is now explicitly uint8_t, which packs it alongside
m_hasDefaultCancelledValue for 78 -> 80. The constructor's initializer list is
reordered to match the new declaration order.

In AutomationState, pair up time1/time2 and value1/value2 rather than
interleaving them, and make eventIndex a size_t instead of an int -- it indexes
m_events, so it was the wrong type as well as the cause of the trailing hole.

* Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:
(WebCore::AudioParamTimeline::valuesForFrameRangeImpl):
Update the aggregate initializer for the new member order, and drive the event
loop with a size_t index so no conversion is needed at the AutomationState and
processSetTargetFollowedByRamp() call sites. The bounds check becomes
(WebCore::AudioParamTimeline::valuesForFrameRangeImpl):
Update the aggregate initializer for the new member order, and drive the event
loop with a size_t index so no conversion is needed at the AutomationState and
processSetTargetFollowedByRamp() call sites. The bounds check becomes
(WebCore::AudioParamTimeline::valuesForFrameRangeImpl):
Update the aggregate initializer for the new member order, and drive the event
loop with a size_t index so no conversion is needed at the AutomationState and
processSetTargetFollowedByRamp() call sites. The bounds check becomes
(WebCore::AudioParamTimeline::valuesForFrameRangeImpl):
Update the aggregate initializer for the new member order, and drive the event
loop with a size_t index so no conversion is needed at the AutomationState and
processSetTargetFollowedByRamp() call sites. The bounds check becomes
i + 1 < n rather than i < n - 1 to avoid underflow on an empty vector.
(WebCore::AudioParamTimeline::processSetTargetFollowedByRamp):
Take the event index as size_t.

* Source/WebCore/Modules/webaudio/AudioNode.h:
Order the 8-byte members first, then the 4-byte group (the two atomic ref 
counts,
m_channelCount, the two channel enums and m_nodeType), then m_isInitialized with
the other four bools. This closes the 3-byte hole after m_isInitialized, the
4-byte hole before m_logger and the 4-byte trailing hole.

* Source/WebCore/Modules/webaudio/AudioNode.cpp:
(WebCore::AudioNode::AudioNode):
Reorder the initializer list to match, keeping -Wreorder quiet. m_context is
initialized from the constructor parameter, not from m_nodeType, so moving
m_nodeType last is safe.

* Source/WebCore/Modules/webaudio/RealtimeAnalyser.h:
Move m_writeIndex down next to m_shouldDoFFTAnalysis and
m_noiseInjectionPolicies, closing the 4-byte hole it left between
m_inputBuffer and m_downmixBus.

AudioBuffer is left alone: RefCountedBase is exactly 4 bytes with no tail
padding, so m_sampleRate already occupies offset 12 for free and 48 is the
alignment floor. Moving m_sampleRate down beside m_noiseInjectionMultiplier
pushes m_originalLength to offset 16 and grows the class to 56.

These are layout-only changes with no behavior change. The same before/after
layouts were checked against x86_64-pc-windows-msvc and 
x86_64-unknown-linux-gnu,
which save the same 8 bytes per class; 32-bit x86 is size-neutral for AudioNode
and RealtimeAnalyser and still saves 8 for the other two. No bitfields,
no [[no_unique_address]] and no reliance on base-class tail-padding reuse are
involved, and std::optional<SavedEvent> is value-then-flag in both libc++ and
the MS STL.

* Source/WebCore/Modules/webaudio/AudioNode.cpp:
* Source/WebCore/Modules/webaudio/AudioNode.h:
* Source/WebCore/Modules/webaudio/AudioParamTimeline.cpp:
* Source/WebCore/Modules/webaudio/AudioParamTimeline.h:
* Source/WebCore/Modules/webaudio/RealtimeAnalyser.h:

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



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

Reply via email to