SteveSanderson/knockout — pull request #824 by coderenaissance (2013-02-02 05:34:11+00:00)
Title: Fixes issue #823

As described in issue #823;

I have an app allows large numbers of records to be edited locally. Performance degrades severely in older versions of IE because the duplicate dependency tracking uses an array and older IE browsers lack of a native implementation of indexOf. A solution is needed that tracks duplicate dependencies without an array. I'll be making a pull request momentarily, but here is the gist of my proposed solution (which passes unit tests):

registerDependency: function fnRegisterDependency(subscribable) {
if (!ko.isSubscribable(subscribable))
throw new Error("Only subscribable things can act as dependencies");
if (_frames.length > 0) {
var topFrame = _frames[_frames.length - 1];
subscribable.key = subscribable.key || ko.utils.generateRandomId();

if (!topFrame || topFrame.distinctDependencies[subscribable.key])
return;

topFrame.distinctDependencies[subscribable.key] = true;

topFrame.callback(subscribable);
}
},
Note that I exposed generateRandomId via ko.utils for use between modules but did not call exportSymbol on it. For 1000 subscribables in IE8 this function originally took 1460ms. After this change it only took 243ms. In chrome the same example went from 1ms up to 14ms. Despite this small degredation of performance in chrome and likely other modern browsers, I believe it is worth while to lift application performance to a reasonable level in older IE browsers for so long as they are supported.

I am new to this project and hope I understood the intent of the code and that the fix is reasonable. Thanks so much for your consideration.

Dave Herren