[Webkit-unassigned] [Bug 30988] New: Attribute cache purged too eagerly

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Sat Oct 31 21:35:53 PDT 2009


https://bugs.webkit.org/show_bug.cgi?id=30988

           Summary: Attribute cache purged too eagerly
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: All
        OS/Version: All
            Status: UNCONFIRMED
          Severity: Normal
          Priority: P2
         Component: WebCore Misc.
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: jamesr at chromium.org


The following code runs in O(N) time on Firefox and O(N^2) time on WebKit based
browsers:

  var elems = document.getElementsByName('elem_name');
  for (var i=0; i<elems.length; i++) {
    var e = elems.item(i);
    e.className = 'elem_class';
  }

document.getElementsByName() returns a NodeList which is backed by a
WebCore::DynamicNodeList.  The reason for the slowdown is that assigning to
e.className forces the document's entire node list cache to be dumped, even
though the DynamicNodeList backing the 'elems' variable has nothing to do with
the class name attribute.  This means in each loop iteration the 'elems'
variable has to be recalculated by evaluating every node in the entire DOM to
see if its name is 'elem_name'.  There's two obvious optimizations that can be
made:

1) When an attribute is mutated only purge node list caches associated with the
attribute mutated
2) When an attribute with value X has X written into it (i.e. if the className
was already 'elem_class' in this example), do not purge any node list caches

It's of course possible to rewrite the javascript snippet to perform much
better by copying the elements in 'elems' into a javascript array before
mutating them, but I think the javascript is fairly idiomatic and reasonable. 
Additionally since Firefox performs fine on this code developers are less
likely to notice how badly this performs.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list