XSLT 性能 [英] XSLT Performance

查看:63
本文介绍了XSLT 性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个包含许多 XSLT 转换的项目工作.转换必须尽可能快.

I am working for a project which has many XSLT transformations. The transformations have to be as fast as possible.

为了可读性,我写了许多将业务逻辑"和输出".例如

For readability I wrote many of them dividing "business logic" and "output". For example

<!-- Business Logic -->
 <xsl:variable name="myLocalVar">
      <xsl:value-of select="func:whateverComputation(params)" />
</xsl:variable>

<!-- more buss logic here -->

<!-- Output -->
<xsl:element name="mytag">
    <xsl:value-of select="$myLocalVar" />
</xsl:element>

当然这可以写成紧凑的形式

Of course this can be written in a compact form

<xsl:element name="mytag">
      <xsl:value-of select="func:whateverComputation(params)" />
</xsl:element>

第一种形式比第二种形式慢吗?

推荐答案

将函数应用的结果保存到变量中不会对性能产生任何重大影响在一般情况下(和某些 XSLT 处理器(例如 Saxon)使用惰性求值,因此在实际需要该变量之前不会对函数求值).

Saving the result of function application to a variable isn't going to have any significant impact on performance in the general case (and some XSLT processors such as Saxon use lazy evaluation, so the function will not be evaluated untill the variable is actually needed).

相反,如果函数必须使用相同的参数进行多次计算,将结果保存在变量中在某些情况下会导致显着增加效率.

On the contrary, if the function must be evaluated more than once with the same parameters, saving the result in a variable can result in some cases in significant increase of efficiency.

提高性能的正确方法是:

  1. 分析/衡量以确定真正的瓶颈.

  1. Profile/measure to identify real bottlenecks.

仅优化最大的瓶颈.

如果仍然需要提高性能,请开始新的迭代,转到上面的 1.

If there is still need for increased performance, start a new iteration, going to 1. above.

引用 Donald Knuth 的话说:过早的优化是万恶之源"——这实际上是对著名谚语的转述:道路下地狱是用善意铺就的."

To quote Donald Knuth: "Premature optimization is the root of all evil" -- which is actually a paraphrase of the wellknown saying: "The road to hell is paved with good intentions."

这篇关于XSLT 性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆