Re: [xsl] Performance differences between xsl:for-each and xsl:template matches

Subject: Re: [xsl] Performance differences between xsl:for-each and xsl:template matches
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Aug 2022 05:12:41 -0000
> Well, this appears to be working code, and attempting to improve the
performance
> of working code is not "premature" - provided that you have clear
evidence that
> the working code doesn't meet the performance requirements.

Actually, even with working code it is premature to attempt optimizing any
part of it that has not been shown to be a performance bottleneck.

We all agree that any optimization has to be needs/reality-driven, that is,
optimize only the codes of proven bottlenecks.
In case the transformation is slow, but there have been no measurements
(profiling), attempts to target random types of code (not specific
templates/functions) are exactly that: unjustified, or in other words
"premature" optimization.

Thanks,
Dimitre

On Wed, Aug 17, 2022 at 12:10 AM Michael Kay mike@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> Well, this appears to be working code, and attempting to improve the
> performance of working code is not "premature" - provided that you have
> clear evidence that the working code doesn't meet the performance
> requirements.
>
> What it does appear to be, though, is optimization by trial-and-error,
> which is an equally common fault.
>
> But let's ignore the critique of methodology and try to answer the
> question. There is no reason to believe that using apply-templates and
> template rules should be faster than for-each. On the contrary, one would
> expect it to be marginally slower. The reason for advising people to use
> apply-templates is not for performance improvement, it is to create code
> that is more robust and maintainable.
>
> Michael Kay
> Saxonica
>
> On 16 Aug 2022, at 22:06, Dimitre Novatchev dnovatchev@xxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> To quote Donald Knuth: "Premature optimization is the root of all evil"
>
https://stackify.com/premature-optimization-evil/#:~:text=%E2%80%9CPremature%
20optimization%20is%20the%20root,is%20credited%20to%20Donald%20Knuth
> .
>
> I think he discovered a general law that is true for all overzealous
> believers, as one can find ample proofs looking back in history.
>
> Or, as they say: "The road to hell is paved with good intentions".
>
>
> Thanks,
> Dimitre
>
>
> On Tue, Aug 16, 2022 at 10:11 AM Edward Porter edward.porter@xxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>> I inherited an older stylesheet that makes extensive use of
>> <xsl:for-each> matching elements (e.g., select=b//chapter[@eid]b) in
the
>> root template to then call templates. Using Saxon, would there be any
>> performance improvements if I refactored to use match templates and
>> <xsl:apply-templates> as would generally be the best practice in this
case?
>>
>>
>>
>> -Ed
>>
>>
>>
>>
>>
>> *Edward Porter*
>>
>> Doc Publishing Tech Lead | Documentation Engineering - DevOps
>>
>> Tel: + 1 919 531 2349
>>
>> SAS | 100 Campus Drive | Cary, NC 27513
>>
>>
>>
>> <image001.gif>
>>
>> DID YOU KNOW?
>> *SAS IS THE NO. 1 AI AND ADVANCED ANALYTICS SOFTWARE PLATFORM.
>> <https://www.sas.com/gms/redirect.jsp?detail=GMS114829_158201>*
>>
>>
>>
>>
>> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
>> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
>> email)
>>
>
>
> --
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
> email)
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/782854> (by
> email <>)
>


--
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread