knockout.js is too slow in filling observableArray

2020-07-23 03:16发布

问题:

I create test for the comparing angular and knockout:

    items = self.items();
    // ...
    self.items.valueHasMutated();

http://jsfiddle.net/imbolc/z7bkz/9/embedded/result/

Is this test correct? Do you know way for increase KO filling speed?

回答1:

I did not thoroughly compare the logic betweens your different tests, but I do know that there are some issues with how Chrome processes text nodes as described here: https://github.com/SteveSanderson/knockout/issues/793

If you strip the text nodes from your inline KO template, then you see a big boost in performance in Chrome.

Like:

<ul id="ko-list" data-bind="foreach: items"><li>ko: <span data-bind="text: val"></span></li></ul>

Updated sample: http://jsfiddle.net/rniemeyer/tsTmZ/

Sample results in the latest Chrome:

jquery: 45 ms 74 ms

angular: 171 ms 199 ms

knockout: 109 ms 25 ms