Performance -- Re: [xsl] RE:"*NEVER* use for-each"

Subject: Performance -- Re: [xsl] RE:"*NEVER* use for-each"
From: "Anjul Srivastava" <anjul@xxxxxxxxxxx>
Date: Tue, 27 Feb 2001 12:38:39 -0800
> In this age of huge storage devices, ridiculously fast machines, and
> OSes, the art of optimization is dwindling.  People just don't get how
> important optimizing for speed can be.  In my case, I MUST be concerned
> speed and size and will likely use a for-each (if I see a gain in testing)
> over the "correct" method of using templates.  Response time is that
> important.

I have seen far too many projects being ruined because somebody chose one
design over the other because of O(1) performance issues. Unless you are
programming the space shuttle, O(1) performance comes LAST, and definitely
not at the design stage. At the design stage the concerns are: reduction of
complexity (implementation ease), extensibility, reusability, reuse, etc.
Even individually, each of these concerns overrides O(1) performance
considerations, not to talk of all of them put together.

O(1) Performance comes last. When you have successfully developed a product
that has made it through the QA cycle, profile  your code and look at your
hot spots. Then see how can you minimally modify your elegant design to
speed up the hot spots. Maybe it might lead you to make your design even
more elegant, but then, probably it won't. But wait, don't go make those
changes yet. Get feedback from your users. Are they finding it slow? Or
would they much rather have you put in your hard work into implementing that
cool feature that didn't make it into this version?

Okay I went back and put O(1) in front of each instance of the performance
work above. Firstly, O(1) performance enhancements are (loosely speaking)
those that improve performance by the same percentage for both large input
and very large input. The advantage of using classes in C++/Java rather than
writing everything in main falls under this category. So does the
performance difference (if any) between xsl:templates and xsl:for-each. A
performance improvements that are not O(1) is using a binary tree instead of
a list to store data that is looked up significantly often.

Usually an intelligent designer will either create an abstract design that
lets you plug in containers of your choice, or he will be able to anticipate
and thus incorporate efficient (in the order sense) containers into his
design up front. Somehow I can't imagine a designer thinking, "Gee, how
would I store the US yellow pages, hmmm.. I think I'll just use a linked

In short, whether or not you use "for-each" should depend upon
non-performance factors, (unless of course you are writing a stylesheet for
use in the spaceshuttle that must be applied within the first three seconds
of reentry).

 XSL-List info and archive:

Current Thread