lndigo
lndigo

Reputation: 113

Choose - When performance with multiple predicates

Suppose you have the following XSL 1.0

<choose>
    <when test="a = 'test' or b = 'test' or c = 'test'">
        // do work
    </when>
    <when test="d = 'test' or e = 'test' or f = 'test">
        // do work
    </when>
</choose>

versus

<choose>
    <when test="a = 'test'">
        // do work
    </when>
    <when test="b = 'test'">
        // do work
    </when>
    <when test="c = 'test'">
        // do work
    </when>
    etc...
</choose>

Obviously, I would prefer the string of predicates versus exploding them into their own separate when elements to be more DRY, but i'm not sure of performance implications as this list may grow to quite a large size. Does the XSL parser create an internal switch-case construct and essentially convert it to:

case a:
case b:
case c:
    //do work
break;

In which case exploding the when element would be premature optimization? Is there a better XSL pattern for handling such a problem?

Upvotes: 0

Views: 27

Answers (1)

Michael Kay
Michael Kay

Reputation: 163587

Optimization and performance depend on the processor. For this case the answer will even vary between Saxon-HE and Saxon-EE. The question can't be answered without knowing which processor you are using.

But it's unlikely to be a make-or-break optimization. If you have a performance problem and you suspect that this is the cause, then experiment with different ways of writing it and measure the impact.

Upvotes: 1

Related Questions