Re: Optimizing a schema.

Casey,

The only formal method is to create a series of style rules to evaluate input against.  To improve processing speed I recommend setting the input to an array and splitting each element into its own index of that array.  When the presence of an element fails one of your style rules convert that element into an empty string, but do not remove the index.  Splicing arrays is extremely slow in JavaScript.  DOM methods are also extremely slow, so do not use them.  Instead use the join method on your array and output the array using a single innerHTML method if in a browser or document.write from a command line interpreter.  Eliminating DOM methods from JavaScript will reduce processing time to as much as one forth the original time.  Eliminating a series of splice methods in addition to removing DOM methods from your JavaScript can push your code from being four times faster to as much as six times faster to evaluate.

I recommend passing through the entire array once without any recursive logic and performing separate iterative evaluations, such as a function call from inside a loop that returns prematurely only when changes no longer occur.

If possible I would avoid my prior suggestions as much as possible by forcing as much of this automation into your XSLT engine and performing as little effort as possible within your JS code.

Austin Cheney

Received on Thursday, 22 July 2010 11:52:29 UTC