The reason DoT is fast is not due to string concatenation (it is still
an order of magnitude faster than interpreting string manipulation
templating engines). The secret sauce is dynamic function generation.
This pattern is not reserved for any particular process and can be
applied whenever there is repetitive state manipulation. I don't know
the specifics of the Knockout implementation, but we use the same
pattern in our database engine (we generate execution function
corresponding to a SQL query. We can then call the ready made function
with the new input parameters whenever a similar SQL query is posed).
Once you travelled down that path, you will find that complexity does
not increase but rather decreases. The generated manipulator functions
can be inspected and debugged much easier than tiresome and complex
workings of the interpreting code that reads the declarative data.
To be more precise:
A) We have a current DOM state generated by a rule/template
B) We have type of model change relating to A)
C) Our aim is to get to the future DOM state C)
D) Lets generate a Javascript function that transforms A) to C) using
B)
E) Save D in a dictionary for reuse using template A) and change type
B) as key
F) Whenever we need to apply B) we look it up in E) and call D) on A).
This will be the fastest way to get to C)
Imho, this would make Knockout up to a hundred times faster.
On Dec 28, 4:39 am, EntitySpaces <
entityspa...@gmail.com> wrote:
> Actually, if you run his original sample in IE 9 it takes anywhere
> from 8 to 9 seconds, amazingly, the doT template sample posted herehttp://
jsfiddle.net/StarcounterJack/Fe2Dr/runs in 6 milliseconds,