Debounce change events to prevent event.on/event.off storm on batch change#22
Debounce change events to prevent event.on/event.off storm on batch change#22anton-ryzhov wants to merge 5 commits intoractivejs:masterfrom
event.on/event.off storm on batch change#22Conversation
|
Hmm, I'm experiencing some issues after this patch. I'm going to analyze it deeply. |
|
You don't have to edit the |
|
I've found problem and fixed it. Works good for me. Do you think this PR useful for the project? Are you going to merge it, should we think how to fix the tests? |
|
Now that we're using mocha, we can do async tests: it("should work", function (done) {
model.on('change:message', function (value) {
expect(value).to.eql('hi');
done();
});
model.set('message', 'hi');
});Can you see if you can update the tests where it fails? Also, would you get the same benefit if you set |
|
Yes, I've googled for mocha async. We have to |
|
i tried to update the test accordingly (but didn't commit it): https://gist.github.com/rstacruz/6444768b890ac4f0f6a6#file-ractive-test-diff it seems to work perfectly :) |
|
Tricky a little bit, isn't it? Also http://underscorejs.org/#defer may be useful as far we use |
|
It looks like |
|
Oh no, I've said about But inside main code they have huge difference. |
|
I've tested your idea about |
|
+Fixed unittests |
😧 Thanks for flagging this @anton-ryzhov - no question that there's a major problem here. I haven't looked into it at all, but is there any way of solving it without debouncing (a flag on the list.push({ foo: 'bar' });
ractive.set( 'listHeight', ractive.find( 'ul' ).offsetHeight );I get a chance today I'll have a poke as well |
|
I've found this bug in one case:
Internally we have these steps:
Maybe there is another reproduce scenarios in some rare cases, but this is definitely one of the most frequent. This lib should listen to Looks like Now I don't know better way than decorating/wrapping Any another ideas? |
|
#28 replaces this PR |
When
ractivedisplaysbackbone's collection, it monitors events on collection itself and its models.When we do
collection.fetch()it triggersset/reset, on collection andaddon each model.Ractivedoes huge work onadd, resetting event handlers, updates parent keypathes, etc.As result — loading and displaying 20 models took ~1500 calling of
changeHandlerand 1.2 seconds on my machine (according toconsole.time/timeEnd).I've added
underscore.debounce(as far we already depend onunderscorethroughbackbone) to decrease change event triggering times.This will slowdown rerender after atomic update for
debounceInterval(50 msec), but add huge speedup in batch changes. In my case, 20 models — 30 calls ofchangeHandlerand 30 msec total time. 40 times faster!Actually I've got the same result with
debounceInterval=10, but I think 50 is good balance between processing in slow browser and responsiveness in fast one.