1

Here is links to my files XML, XSLT, Include XSLT

Hi

I am transforming xml into html. My xml file is about 10kb big and my xslt 70kb and output html about 10kb big.

Transformer xformer = StylesheetCache.newTransformer(templateFile);
xformer.transform(new DOMSource(outlineDoc),new StreamResult(out));

The creating of the transformer takes about 10s to create thats why i created cache that bring it down to 300ms if its cached. The transform line takes 3s to execute. Now is this long. I have written similar transforms on windows mobile and it execution time is about <=1s

I changed the TransformerFactory to Saxon but the result was about the same.

thanks

Rupesh Yadav
  • 12,096
  • 4
  • 53
  • 70
Pintac
  • 1,565
  • 3
  • 21
  • 38
  • 1
    That is way to much for a 10k XML file. My guess is that you have some really time consuming XPath queries in your XSLT. – Per T Sep 15 '10 at 15:02
  • 3
    As for Saxon, I think Michael Kay always points out that you should use Saxon's tree representation, not a DOM tree as the input, if you are after performance. I don't know whether you already have a DOM tree and need to transform that or whether you have only built that DOM to have an input for XSLT, in the latter case let Saxon choose its tree model by providing a StreamSource or a SAXSource. As for improving the XSLT code, of course if you use Saxon 9, then make sure you take advantage of XSLT 2.0 features like for-each-group, and use keys otherwise where possible to improve performance. – Martin Honnen Sep 15 '10 at 16:43
  • @Pintac: Besides the use of external DOM API or XSLT processor built-in tree parser, If you don't provide an stylesheet and input sample then it's not posible to tell if this is because a bad transformation pattern and it makes your question more appropiate for `xsltprocessor` tag. –  Sep 15 '10 at 17:55
  • I added links to xslt and xml. – Pintac Sep 16 '10 at 07:29
  • @Martin I have a DOM Document i load from file and then change a bit. – Pintac Sep 16 '10 at 08:48
  • @Pintac: I see in your stylesheets mostly a bad design. First, those `choose` for formatting diferent data type and those all over the place `call-template` look that they can benefit from pattern matching (Is your input schema well known?) or some inline map. –  Sep 16 '10 at 17:53
  • Hi. But will this decrease the processing time that much. Like i said below i used msxml xslttransformer and it was ms. – Pintac Sep 17 '10 at 06:40

3 Answers3

4

You problem is with use of DOMSource, don't use it if at all possible. Saxon specifically has much worse performance compared to using a streaming source or SAX source -- this because it builds its own highly optimized (for xslt use) tree ("tiny tree"). There is a work-around to this problem as well as full explanation at: http://dev.saxonica.com/blog/mike/2007/03/#000138.

But even if you were using Xalan (JDK default), it makes sense to use raw input and not build intermediate DOM structure; XSLT processors can build optimal in-memory representation themselves and often more efficiently.

Dawood ibn Kareem
  • 77,785
  • 15
  • 98
  • 110
StaxMan
  • 113,358
  • 34
  • 211
  • 239
  • hiI dont have AugmentedSource in android. I changed the domsource to a streamsource and a saxsource but the processing time still stayed the same. – Pintac Sep 16 '10 at 07:26
  • Ok, that is unexpected. And you are sure you are using Saxon, not default implementation (Xalan)? For me difference was very noticeable, time went down by 50% or so when I made changes, but this was on regular Java SE not Android. This does sound like problem is with stylesheet itself, not xslt processor. – StaxMan Sep 16 '10 at 17:33
  • hi. Yip i use SAXTransformerFactory.newinstance(). I suspected it mite be the xslt but if i run the exact same xslt on msxml xslt transforner is milliseconds – Pintac Sep 17 '10 at 06:39
  • Yeah; creating new transformer factory is wasteful, but that'd just add a millisecond or two -- your timing sounds very much worse, which is why I think it's the stylesheet that does something very slow (sorry didn't yet look at linked to files so no idea what) – StaxMan Sep 17 '10 at 19:27
1

I found the problem... I think i need to kick myself. I was at home playing with my phone so i decided to play with the app a bit. and all of a sudden the init load was like 1s and subsequent calls like 500ms. So at this point i was stumped. i so pulled out my laptop plugged my phone in and debugged and all of a suddend it was 12s again. i was the freaking IDE. as soon as i run it through ecclipse it slows down to 12s.

:-\

Pintac
  • 1,565
  • 3
  • 21
  • 38
0

Are you experiencing such delays on each transformation? I've noticed that when it takes a while for Android to load the third-party libraries into the process. The exact time depends on the library size. For example loading joda-time takes approximately 3 seconds.

nixau
  • 1,095
  • 1
  • 14
  • 27