<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>308946</bug_id>
          
          <creation_ts>2026-03-01 19:48:16 -0800</creation_ts>
          <short_desc>contain: layout causes ~8x regression in forced synchronous reflow on in-flow elements</short_desc>
          <delta_ts>2026-03-28 23:08:03 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Layout and Rendering</component>
          <version>Safari 26</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 26</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>chenglou92</reporter>
          <assigned_to name="Yulun Wu">yulun_wu</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>karlcow</cc>
    
    <cc>simon.fraser</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>zalan</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2186022</commentid>
    <comment_count>0</comment_count>
      <attachid>478537</attachid>
    <who name="">chenglou92</who>
    <bug_when>2026-03-01 19:48:16 -0800</bug_when>
    <thetext>Created attachment 478537
Repro

Adding contain: layout (or contain: strict, contain: content, contain: size layout) to in-flow position: relative elements causes a ~7-8x performance regression
during interleaved read/write DOM access patterns (forced synchronous reflow), compared to the same elements without containment.

overflow: hidden on in-flow elements exhibits the same regression.

Repro:

1. Open the attached HTML file
2. Observe the printed timing ratio

Expected: contain: layout should be equal or faster than baseline, since it restricts layout scope.

Actual: contain: layout is ~7-8x slower than baseline.

Test results on Safari
baseline (position:relative):  ~69ms
+ contain:layout:              ~539ms
ratio:                         ~7.8x

Chrome, same hardware &amp; OS:
baseline (position:relative):  ~43ms
+ contain:layout:              ~32ms
ratio:                         ~0.75x  (faster, as expected)

Batched access (all writes then all reads) shows no regression — both ~4-6ms. The issue is specific to forced synchronous reflow triggered by interleaved
write-then-read patterns.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2186210</commentid>
    <comment_count>1</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2026-03-02 11:22:09 -0800</bug_when>
    <thetext>Surprising!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2186211</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2026-03-02 11:22:16 -0800</bug_when>
    <thetext>&lt;rdar://problem/171545381&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2186218</commentid>
    <comment_count>3</comment_count>
    <who name="Simon Fraser (smfr)">simon.fraser</who>
    <bug_when>2026-03-02 11:47:29 -0800</bug_when>
    <thetext>(Look at the relative %, not the actual %):

Without contain:

Sample Count, Samples%, Normalized CPU %, Symbol
24, 26.7%, 1.2%, WebCore::Element::offsetHeight() (in WebCore)
24, 26.7%, 1.2%,     WebCore::Document::updateLayoutIfDimensionsOutOfDate(WebCore::Element&amp;, WTF::OptionSet&lt;WebCore::DimensionsCheck, (WTF::ConcurrencyTag)0&gt;, WTF::OptionSet&lt;WebCore::LayoutOptions, (WTF::ConcurrencyTag)0&gt;) (in WebCore)
22, 24.4%, 1.1%,         WebCore::Document::updateLayout(WTF::OptionSet&lt;WebCore::LayoutOptions, (WTF::ConcurrencyTag)0&gt;, WebCore::Element const*) (in WebCore)
22, 24.4%, 1.1%,             WebCore::LocalFrameViewLayoutContext::layout(bool) (in WebCore)
22, 24.4%, 1.1%,                 WebCore::LocalFrameViewLayoutContext::performLayout(bool) (in WebCore)
13, 14.4%, 0.7%,                     WebCore::LocalFrameViewLayoutContext::flushUpdateLayerPositions() (in WebCore)
13, 14.4%, 0.7%,                         void WebCore::RenderLayer::recursiveUpdateLayerPositions&lt;(WebCore::RenderLayer::UpdateLayerPositionsMode)0&gt;(WTF::OptionSet&lt;WebCore::RenderLayer::UpdateLayerPositionsFlag, (WTF::ConcurrencyTag)0&gt;) (in WebCore)
9, 10.0%, 0.5%,                     WebCore::RenderView::layout() (in WebCore)
9, 10.0%, 0.5%,                         WebCore::RenderBlock::layout() (in WebCore)
9, 10.0%, 0.5%,                             WebCore::RenderBlockFlow::layoutBlock(WebCore::RelayoutChildren, WebCore::LayoutUnit) (in WebCore)
9, 10.0%, 0.5%,                                 WebCore::RenderBlockFlow::layoutBlockChildren(WebCore::RelayoutChildren, WebCore::LayoutUnit&amp;) (in WebCore)
9, 10.0%, 0.5%,                                     WebCore::RenderBlockFlow::layoutBlockChild(WebCore::RenderBox&amp;, WebCore::RenderBlockFlow::MarginInfo&amp;, WebCore::LayoutUnit&amp;, WebCore::LayoutUnit&amp;) (in WebCore)
3, 3.3%, 0.2%,                                         WebCore::RenderBox::avoidsFloats() const (in WebCore)


With contain:

Sample Count, Samples%, Normalized CPU %, Symbol
304, 48.3%, 2.1%, WebCore::Element::offsetHeight() (in WebCore)
304, 48.3%, 2.1%,     WebCore::Document::updateLayoutIfDimensionsOutOfDate(WebCore::Element&amp;, WTF::OptionSet&lt;WebCore::DimensionsCheck, (WTF::ConcurrencyTag)0&gt;, WTF::OptionSet&lt;WebCore::LayoutOptions, (WTF::ConcurrencyTag)0&gt;) (in WebCore)
299, 47.5%, 2.1%,         WebCore::Document::updateLayout(WTF::OptionSet&lt;WebCore::LayoutOptions, (WTF::ConcurrencyTag)0&gt;, WebCore::Element const*) (in WebCore)
299, 47.5%, 2.1%,             WebCore::LocalFrameViewLayoutContext::layout(bool) (in WebCore)
299, 47.5%, 2.1%,                 WebCore::LocalFrameViewLayoutContext::performLayout(bool) (in WebCore)
287, 45.6%, 2.0%,                     WebCore::RenderView::layout() (in WebCore)
287, 45.6%, 2.0%,                         WebCore::RenderBlock::layout() (in WebCore)
287, 45.6%, 2.0%,                             WebCore::RenderBlockFlow::layoutBlock(WebCore::RelayoutChildren, WebCore::LayoutUnit) (in WebCore)
287, 45.6%, 2.0%,                                 WebCore::RenderBlockFlow::layoutBlockChildren(WebCore::RelayoutChildren, WebCore::LayoutUnit&amp;) (in WebCore)
287, 45.6%, 2.0%,                                     WebCore::RenderBlockFlow::layoutBlockChild(WebCore::RenderBox&amp;, WebCore::RenderBlockFlow::MarginInfo&amp;, WebCore::LayoutUnit&amp;, WebCore::LayoutUnit&amp;) (in WebCore)
209, 33.2%, 1.5%,                                         WebCore::RenderBlock::createsNewFormattingContext() const (in WebCore)
20, 3.2%, 0.1%,                                         WebCore::RenderBlock::layout() (in WebCore)
20, 3.2%, 0.1%,                                             WebCore::RenderBlockFlow::layoutBlock(WebCore::RelayoutChildren, WebCore::LayoutUnit) (in WebCore)
16, 2.5%, 0.1%,                                                 WebCore::RenderBlockFlow::layoutBlockChildren(WebCore::RelayoutChildren, WebCore::LayoutUnit&amp;) (in WebCore)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2192309</commentid>
    <comment_count>4</comment_count>
    <who name="Yulun Wu">yulun_wu</who>
    <bug_when>2026-03-20 22:59:42 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/61069</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2194808</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2026-03-28 23:08:00 -0700</bug_when>
    <thetext>Committed 310173@main (541a1c2870a0): &lt;https://commits.webkit.org/310173@main&gt;

Reviewed commits have been landed. Closing PR #61069 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>478537</attachid>
            <date>2026-03-01 19:48:16 -0800</date>
            <delta_ts>2026-03-01 19:48:16 -0800</delta_ts>
            <desc>Repro</desc>
            <filename>safari-contain-repro.html</filename>
            <type>text/html</type>
            <size>1633</size>
            <attacher>chenglou92</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KPG1ldGEgY2hhcnNldD0idXRmLTgiPgo8dGl0
bGU+U2FmYXJpIGNvbnRhaW46IGxheW91dCByZWdyZXNzaW9uIHJlcHJvPC90aXRsZT4KPC9oZWFk
Pgo8Ym9keT4KPHByZSBpZD0ib3V0Ij48L3ByZT4KPGRpdiBpZD0iYzEiPjwvZGl2Pgo8ZGl2IGlk
PSJjMiI+PC9kaXY+CjxzY3JpcHQ+CmZ1bmN0aW9uIHNldHVwKGNvbnRhaW5lcikgewogIGNvbnRh
aW5lci5zdHlsZS5jc3NUZXh0ID0gInBvc2l0aW9uOnJlbGF0aXZlIjsKICBmb3IgKGxldCBpID0g
MDsgaSA8IDUwMDsgaSsrKSB7CiAgICBjb25zdCBkID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgi
ZGl2Iik7CiAgICBkLnN0eWxlLmNzc1RleHQgPSAicG9zaXRpb246cmVsYXRpdmU7d2lkdGg6MjAw
cHg7cGFkZGluZzoycHggNHB4O2JvcmRlcjoxcHggc29saWQgI2NjYyI7CiAgICBkLnRleHRDb250
ZW50ID0gIndvcmQgIi5yZXBlYXQoNSk7CiAgICBjb250YWluZXIuYXBwZW5kQ2hpbGQoZCk7CiAg
fQogIHZvaWQgY29udGFpbmVyLm9mZnNldEhlaWdodDsKICByZXR1cm4gQXJyYXkuZnJvbShjb250
YWluZXIuY2hpbGRyZW4pOwp9CgpmdW5jdGlvbiB0aHJhc2gobm9kZXMpIHsKICBjb25zdCB3aWR0
aHMgPSBbMTgwLCAyMDAsIDE5MCwgMjEwLCAxOTUsIDIwNSwgMTg1LCAyMTVdOwogIGxldCBzaW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