<?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>119114</bug_id>
          
          <creation_ts>2013-07-25 17:05:49 -0700</creation_ts>
          <short_desc>Avoid N^2 walk placing renderers when building the render tree</short_desc>
          <delta_ts>2013-11-06 23:09:36 -0800</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>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BlinkMergeCandidate</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ryosuke Niwa">rniwa</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>hyatt</cc>
    
    <cc>kling</cc>
    
    <cc>koivisto</cc>
    
    <cc>leviw</cc>
    
    <cc>simon.fraser</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>911806</commentid>
    <comment_count>0</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2013-07-25 17:05:49 -0700</bug_when>
    <thetext>Consider merging https://chromium.googlesource.com/chromium/blink/+/51dbeeec81d866ba47a04da2cd2bf7ab200d32f6
or come up with a better fix.

Blink resolves style by walking each element from first children to last, but
when we go to insert their renderer, we look for the next renderer to insert
before. On the initial style resolve, this means we&apos;ll walk the entire DOM
tree trying to find the right renderer to insert before leading to an N^2
loop over the DOM on load.

This could be fixed by changing the semantics by which we insert renderers
(insert after instead of insert before). Instead, here I reverse the order
we resolve style. This should ensure that in the common case, we&apos;ll find
the renderer to insert before immediately.

While looking at this, I also found we have an N^2 loop for resolving
Nth last child selectors, and reversing the style resolve loop would have
caused the same issue for Nth child selectors. To fix prevent this regression,
I&apos;m piping the child index down to the style resolver in the common case.
This ensures both Nth and Nth last should usually be O(1).

The previous version of this patch resulted in a perf regression due to
the extra in-order loop in Element::recalcStyle. This loop is now gated
on the presence of child or sibling selectors. The common case should
be faster.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>911838</commentid>
    <comment_count>1</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2013-07-25 19:07:17 -0700</bug_when>
    <thetext>Partially reverted in https://chromium.googlesource.com/chromium/blink/+/6d7c7f5fa9535b5bb52c4d8c407cc078183bd6df.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>911839</commentid>
    <comment_count>2</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2013-07-25 19:21:52 -0700</bug_when>
    <thetext>Fully reverted in https://chromium.googlesource.com/chromium/blink/+/4bab7e7cb5d1001480c42ebad633818b2771b140.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>948084</commentid>
    <comment_count>3</comment_count>
    <who name="Ryosuke Niwa">rniwa</who>
    <bug_when>2013-11-06 23:09:36 -0800</bug_when>
    <thetext>Also see https://src.chromium.org/viewvc/blink?revision=159037&amp;view=revision and https://src.chromium.org/viewvc/blink?revision=159190&amp;view=revision</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>