You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Kelly Davis <th...@yahoo.com> on 2012/10/25 16:12:02 UTC

Performance of DOMNodeList in form loops

In our code we have many loops of the form....

XMLCh *namespace = ...                               
XMLCh *elementName = ...         
DOMNodeList *domNodeList =  domElement->getElementsByTagNameNS(namespace, elementName);                                
XMLSize_t domNodeListSize = domNodeList->getLength();           
for (XMLSize_t count = 0; count < domNodeListSize; ++count) {                                           
    DOMElement *nextDOMElement = (DOMElement *) domNodeList->item(count);
    // Modify nextDOMElement by adding attributes
}

These are extremely slow.

The problem seems to be multi-fold:

1. The API has no getElementsByTagNameNS() that returns a "const DOMNodeList*", thus allowing optimizations. (Not xerces-c's fault, but it's a nice-to-have!)
2. DOMNodeList:: getLength() is order O(V + E), where V is the number of DOMElements under domElement and E is the number of edges
3. DOMNodeList:: item(XMLSize_t index) is of oder O(V + E) as nextDOMElement's attributes are modified and thus the DOMDocument's fChanges is incremented

These yield a for loop that is of O((V + E)^2), which for the number of such loops we have is far, far to slow.

Short of re-writing DOMDeepNodeListImpl, what is the proper solution to this problem?

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org


Re: Performance of DOMNodeList in form loops

Posted by Ben Griffin <be...@redsnapper.net>.
Why not load up XQilla and use xpaths?
Or maybe write your code in XSLT, XQuery or even Obyx.

On 25 Oct 2012, at 15:12, Kelly Davis <th...@yahoo.com> wrote:
> In our code we have many loops of the form....
> 
> XMLCh *namespace = ...                               
> XMLCh *elementName = ...         
> DOMNodeList *domNodeList =  domElement->getElementsByTagNameNS(namespace, elementName);                                
> XMLSize_t domNodeListSize = domNodeList->getLength();           
> for (XMLSize_t count = 0; count < domNodeListSize; ++count) {                                           
>     DOMElement *nextDOMElement = (DOMElement *) domNodeList->item(count);
>     // Modify nextDOMElement by adding attributes
> }
> 
> These are extremely slow.
> 
> The problem seems to be multi-fold:
> 
> 1. The API has no getElementsByTagNameNS() that returns a "const DOMNodeList*", thus allowing optimizations. (Not xerces-c's fault, but it's a nice-to-have!)
> 2. DOMNodeList:: getLength() is order O(V + E), where V is the number of DOMElements under domElement and E is the number of edges
> 3. DOMNodeList:: item(XMLSize_t index) is of oder O(V + E) as nextDOMElement's attributes are modified and thus the DOMDocument's fChanges is incremented
> 
> These yield a for loop that is of O((V + E)^2), which for the number of such loops we have is far, far to slow.
> 
> Short of re-writing DOMDeepNodeListImpl, what is the proper solution to this problem?
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
> 


Re: Performance of DOMNodeList in form loops

Posted by Alberto Massari <Al...@progress.com>.
Hi Kelly,
given your requirements, have you tried using the 
createNodeIterator/createTreeWalker APIs exposed by DOMDocument?

Alberto

Il 25/10/2012 16:12, Kelly Davis ha scritto:
> In our code we have many loops of the form....
>
> XMLCh *namespace = ...
> XMLCh *elementName = ...
> DOMNodeList *domNodeList =  domElement->getElementsByTagNameNS(namespace, elementName);
> XMLSize_t domNodeListSize = domNodeList->getLength();
> for (XMLSize_t count = 0; count < domNodeListSize; ++count) {
>      DOMElement *nextDOMElement = (DOMElement *) domNodeList->item(count);
>      // Modify nextDOMElement by adding attributes
> }
>
> These are extremely slow.
>
> The problem seems to be multi-fold:
>
> 1. The API has no getElementsByTagNameNS() that returns a "const DOMNodeList*", thus allowing optimizations. (Not xerces-c's fault, but it's a nice-to-have!)
> 2. DOMNodeList:: getLength() is order O(V + E), where V is the number of DOMElements under domElement and E is the number of edges
> 3. DOMNodeList:: item(XMLSize_t index) is of oder O(V + E) as nextDOMElement's attributes are modified and thus the DOMDocument's fChanges is incremented
>
> These yield a for loop that is of O((V + E)^2), which for the number of such loops we have is far, far to slow.
>
> Short of re-writing DOMDeepNodeListImpl, what is the proper solution to this problem?
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
> For additional commands, e-mail: c-dev-help@xerces.apache.org
>
> .
>


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscribe@xerces.apache.org
For additional commands, e-mail: c-dev-help@xerces.apache.org