Why are you wrapping the NodeInfo rather than accessing it directly?  This method is already tied to the Saxon interface so there is no portability issue to deal with.  I would use the NodeInfo directly, and pass in the fingerprint rather than the attribute name to avoid calculating the fingerprint more than once.

You should also check the main application logic - is it possible you are calling this method too many times, i.e. more than once for the same node?  Even with the memory allocation involved in wrapping the node 30% still sounds a bit high.

Taking the wider view, you have missed out what might be an important piece - the XPath expression you are using.  If this is relatively simple then the whole process could be speeded up by using a SAX content handler instead of an XPath evaluator - this avoids building a node tree. 

A useful tip for performance issues - the problems are almost always in the overall shape of the application rather than in the detail of a particular method, in other words you get most benefit by paying attention to the design rather than the detail implementation.  Profilers unfortunately only tell you about the detail implementation.

Best regards,
Trevor Nash

Shridhar Venkatraman wrote:
Hi,

We are using Java to parse xml messages coming at us from a queue.

The XML is simple in structure;

<DESET  SOURCE="TRANSFORM" VERSION="01" TIMESTAMP="2008-10-16 10:12:52.0" ERROR="0">
    <DE NAME = "TRANSACTIONID" TYPE = "LONG"   VALUE = "1"/>
    <DE NAME = "ACCTTYPE"      TYPE = "STRING" VALUE = "01"/>
    around 50 instances of 'DE'
</DESET>

We load it into a document this way;

      byte[] mybyte = txnstatsxml.trim().getBytes();
      java.io.ByteArrayInputStream bais = new java.io.ByteArrayInputStream(mybyte);
      InputSource is = new InputSource(bais);
      SAXSource ss = new SAXSource(is);
      doctxnstats = ((net.sf.saxon.xpath.XPathEvaluator) xpath).setSource(ss);


We then use compiled expressions to search for nodes like so;

n = (List) expr_DESET_DE.evaluate(doctxnstats, XPathConstants.NODESET);

When we find the nodes we look for attributes by calling this helper method like so;

private String getNodeAttr(NodeInfo node, String attr) {
    try {
         return NodeOverNodeInfo.wrap(node).getAttributes().getNamedItem(attr).getNodeValue();
        } catch (Exception e) { }
    return null;
 }

The above method is eating 30% of the cpu used by our message consumer (70% includes MQ interfaces, some SQL inserts  and related commits) according to the profiler. It is invoked very often. Is there is a way to speed this attribute 'getting'? These messages come at us over 500 a sec.

Regards
sV



------------------------------------------------------------------------------

_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help

-- 
Melvaig Technologies Limited
voice:     +44 (0) 1445 771363 
email:     tcn@melvaig.co.uk       web:       http://www.melvaig.co.uk

Registered in Scotland No 194737
5 Melvaig, Gairloch, Ross-shire IV21 2EA