gerich-home / it-depends

Lightweight dependency tracking library for JavaScript
http://it-depends-js.github.io/
Other
1 stars 2 forks source link

Fix performance for diamond dependencies #41

Open gerich-home opened 8 years ago

gerich-home commented 8 years ago

See test from ee7a3537d1430bcc7e9c4eef5a430bdcf7cfb6ec

Perf results on my local machine are:

 'computed diamond updated 1000 times with 500 hidden dependencies'
     'knockout' is etalon
     'itDepends' at 1066.24x slower
gerich-home commented 8 years ago

Seems that the solution is to move postpone the resubscribing (https://github.com/gerich-home/it-depends/blob/master/src/computed.ts#L113) until value.write ends. However this requires redisigning notification code a bit

VanDalkvist commented 8 years ago
'computed diamond updated 1000 times with 500 hidden dependencies' 
Passed:
     'knockout' is etalon
     'itDepends' at 2803.88x slower

2803.88x - :disappointed:

gerich-home commented 8 years ago

Yeah.. Working on it, has some ideas, similar in design to bulkChange.ts

VanDalkvist commented 8 years ago

Maybe I'm wrong but it seems you forgot

      e.subscribe(function () {
      });

for knockout setup after

var e = ko.pureComputed(function() {
       return d() % 2 == 0 ? b() : c();
});

Or it was in purpose? Because you have

var s = e.onChange(function(){
});

for it-depends setup

VanDalkvist commented 8 years ago

In this case performance logs become more real:

'computed diamond updated 1000 times with 500 hidden dependencies' (passed: 2, failed: 0)
     Passed:
       'knockout' is etalon
       'itDepends' at 56.81x slower
Finished 'performance-test-computedDiamondUpdates' after 36 s
gerich-home commented 8 years ago

Correct... found it independently and pushed to branch diamond-performance