KnockoutJS performance

Showing 1-8 of 8 messages
KnockoutJS performance nowamasa 1/3/12 6:18 AM
We have a list widget that's managed by Knockout (using the mapping
plugin), and it works well in Chrome, Firefox and Opera, but
performance is horribly slow in IE7&8 (surprise!).

I've extracted the relevant code to jsFiddle to demonstrate the
problem - it updates a list of 200 items (when you click on the list),
and the time taken for each update (on my PC running Windows 7 64-bit)
is as follows:

Chrome:     ~ 319 ms
Firefox:      ~ 423 ms
Opera:       ~ 566 ms
IE7:          ~3488 ms
IE8:          ~3542 ms

The two things I'd like to know are:

* From this code sample, are we using Knockout correctly? Can we
improve performance generally by doing anything different?
* Is there anything specific we can do to improve performance in IE?
Re: KnockoutJS performance nowamasa 1/3/12 6:19 AM
Re: KnockoutJS performance Guhe Louis 4/26/12 9:05 PM
Well, imho the simpliest solution is don't use knockout's template engine, use jquery template engine insead. Knockout does support the jquery template engine in the newest version.

Re: KnockoutJS performance Michael Best 4/26/12 11:54 PM
It seems that over half the time is from the mapping call, and the
rest is from updating the bindings. I'm not so familiar with the
mapping plugin, but you might try changing your code to update your
view model directly instead of using the plugin.

Also you could try using the 2.1 version of Knockout that has some
performance improvements.
Re: KnockoutJS performance Michael Best 4/27/12 12:26 AM
Here's an example of what I'm talking about:
Re: KnockoutJS performance gaffe 4/27/12 10:32 AM
I also have pages that load some huge viewmodels, lists of like 3000-4000 things are very slow. Good to know mapping might be what is taking a large part of the time. 

I wouldn't use the jquery templates. I moved away from those, the new knockout templates are faster for me not slower. 

Jquery templates can also be a hassle to debug, and can sneak up on you in nasty ways, for example, if you have code like:

data-bind=" event: {change: function() { /*dosomething*/ }}"  the }} characters will be interpreted as a jquery template and you will have errors. 
//if you do use them, the solution is to put a space, like so data-bind="event: {change: function() { /*dosomething*/ } }" by the way

Re: KnockoutJS performance Michael Best 4/27/12 12:49 PM
You can get some extra speed increase (especially with updates) by
using my repeat binding:
Re: KnockoutJS performance 6/15/12 9:54 AM
Don't forget your UI design. If you have Master/Detail like structures, you do two things:

 - Retrieve your data from the server only when needed.
 - Control witch bindings are processed by knockout using conditional bindings.

It explains in more detail <a href="">here</a>, the difference in using the **visible** and the **if** binding.