简体   繁体   English

XSLT转换性能

[英]XSLT Transforming performance

Here is links to my files XML , XSLT , Include XSLT 这是我的文件XMLXSLTInclude XSLT的链接

Hi 你好

I am transforming xml into html. 我正在将xml转换为html。 My xml file is about 10kb big and my xslt 70kb and output html about 10kb big. 我的xml文件约为10kb,我的xslt为70kb,输出的html约为10kb。

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. 创建变压器需要大约10秒钟的时间,这就是为什么我创建了将其缓存到300ms的缓存的原因。 The transform line takes 3s to execute. 转换线需要3秒钟才能执行。 Now is this long. 现在这么长。 I have written similar transforms on windows mobile and it execution time is about <=1s 我在Windows Mobile上编写了类似的转换,其执行时间约为<= 1s

I changed the TransformerFactory to Saxon but the result was about the same. 我将TransformerFactory更改为Saxon,但结果大致相同。

thanks 谢谢

You problem is with use of DOMSource, don't use it if at all possible. 您的问题是使用DOMSource,请尽可能不要使用它。 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"). 与使用流式源或SAX源相比,Saxon的性能特别差-这是因为Saxon会构建自己的高度优化(供xslt使用)的树(“小树”)。 There is a work-around to this problem as well as full explanation at: http://dev.saxonica.com/blog/mike/2007/03/#000138 . 有关此问题的解决方法以及完整的解释,请访问: 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; 但是,即使您使用的是Xalan(默认为JDK),也可以使用原始输入而不构建中间DOM结构。 XSLT processors can build optimal in-memory representation themselves and often more efficiently. XSLT处理器本身可以构建最佳的内存表示形式,并且通常可以更高效地构建它们。

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. 突然间,初始化负载就像1s,随后的调用像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. 我就这样拔出笔记本电脑,插入手机并进行调试,突然又变成了12秒。 i was the freaking IDE. 我是个疯狂的IDE。 as soon as i run it through ecclipse it slows down to 12s. 一旦我通过eclipse运行它,它就会减速到12s。

:-\\ :-\\

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. 我注意到,Android需要一段时间才能将第三方库加载到该过程中。 The exact time depends on the library size. 确切的时间取决于库的大小。 For example loading joda-time takes approximately 3 seconds. 例如,加载joda-time大约需要3秒钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM