[webkit-reviews] review granted: [Bug 74665] Poor XPath performance when evaluating an expression that returns a lot of nodes : [Attachment 119519] proposed fix

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Dec 15 17:02:18 PST 2011


Darin Adler <darin at apple.com> has granted Alexey Proskuryakov <ap at webkit.org>'s
request for review:
Bug 74665: Poor XPath performance when evaluating an expression that returns a
lot of nodes
https://bugs.webkit.org/show_bug.cgi?id=74665

Attachment 119519: proposed fix
https://bugs.webkit.org/attachment.cgi?id=119519&action=review

------- Additional Comments from Darin Adler <darin at apple.com>
View in context: https://bugs.webkit.org/attachment.cgi?id=119519&action=review


> Source/WebCore/xml/XPathNodeSet.cpp:38
> +// When a node set is large, sorting it by traversing the whole document is
better (we can
> +// assume that we aren't dealing with documents that we cannot even traverse
in reasonable time).
> +const unsigned traversalSortCutoff = 10000;

Maybe comparing the node set to the total number of nodes in the document would
be better. I guess we don’t really know what that is, so a hardcoded numbers
seems fine.

> Source/WebCore/xml/XPathNodeSet.cpp:203
> +	   if (node->isAttributeNode())
> +	       containsAttributeNodes = true;

Since isAttributeNode is a virtual function we might want to do the much faster
checks that have flags right in the Node first:

    if (!node->isElementNode() && !node->isTextNode() &&
node->isAttributeNode())

We might even consider putting that optimization into the isAttributeNode
function itself.

> Source/WebCore/xml/XPathNodeSet.cpp:211
> +	   if (nodes.contains(n))
> +	       sortedNodes.append(n);

Would it be more or less efficient to remove each node from the set as it’s
handled?

> Source/WebCore/xml/XPathNodeSet.cpp:216
> +	   if (!containsAttributeNodes || !n->hasAttributes())
> +	       continue;
> +
> +	   NamedNodeMap* attributes = n->attributes();

It would be more efficient to write it like this:

    if (!containsAttributeNodes || !n->isElementNode())
	continue;

    NamedNodeMap* attributes = toElement(n)->attributes(true /* read-only */);
    if (!attributes)
	continue;

Avoids doing some work twice in the hasAttributes and attributes functions.

> Source/WebCore/xml/XPathNodeSet.cpp:226
> +    const_cast<Vector<RefPtr<Node> >& >(m_nodes).swap(sortedNodes);

No need for the space after the "&" character.

Is const_cast preferred over mutable?

I think a typedef for Vector<RefPtr<Node> > would help make this more readable.


More information about the webkit-reviews mailing list