sorting large collections

383 views
Skip to first unread message

Raymond Matos

unread,
Feb 18, 2013, 11:34:28 PM2/18/13
to backbone-...@googlegroups.com
I looking for a good way of sorting and filtering 300 models in a collection.

I have it working using the comparator and it works fine.  My only issue is that its slow!!!

Is there a better way that is faster?




Ruben Vreeken

unread,
Feb 19, 2013, 6:54:52 AM2/19/13
to backbone-...@googlegroups.com
300 items doesn't sound like an awful lot, is the comparator function itself slow?





--
You received this message because you are subscribed to the Google Groups "Backbone.Marionette" group.
To unsubscribe from this group and stop receiving emails from it, send an email to backbone-marion...@googlegroups.com.
To post to this group, send email to backbone-...@googlegroups.com.
Visit this group at http://groups.google.com/group/backbone-marionette?hl=en.
To view this discussion on the web visit https://groups.google.com/d/msg/backbone-marionette/-/yZHDOkv7SQMJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Raymond Matos

unread,
Feb 19, 2013, 10:43:27 AM2/19/13
to backbone-...@googlegroups.com
300 models

this is the code i'm using

view.collection.comparator = function(model) {
    return model.get('name');
}
view.collection.sort();
view.render();

using console.time to time it.

From start to render
sortAZ: 1435.811ms

Seems slow to me.


Ruben Vreeken

unread,
Feb 19, 2013, 11:00:49 AM2/19/13
to backbone-...@googlegroups.com
wow, that does seem slow... could it be that something odd happens when 'getting' the name property?
or does the view re-render each time a comparison is made?

--
You received this message because you are subscribed to the Google Groups "Backbone.Marionette" group.
To unsubscribe from this group and stop receiving emails from it, send an email to backbone-marion...@googlegroups.com.
To post to this group, send email to backbone-...@googlegroups.com.
Visit this group at http://groups.google.com/group/backbone-marionette?hl=en.

Raymond Matos

unread,
Feb 19, 2013, 1:24:21 PM2/19/13
to backbone-...@googlegroups.com
Not sure, but model.get is standard stuff in backbone.  Gonna keep digging 

Robert Levy

unread,
Feb 19, 2013, 1:57:29 PM2/19/13
to backbone-...@googlegroups.com

It smells like the view is re-rendering as items are moved around during the sort.   Quick test for that would be to not hook the collection up to the view until after the sort.

Raymond Matos

unread,
Mar 5, 2013, 4:48:46 PM3/5/13
to backbone-...@googlegroups.com
Yea, i decided to clone the collection, sort the clone collection the overwrite the original collection with 30 modals, render the other models as the user is scrolling.  

Gerard Finnerty

unread,
May 6, 2014, 9:20:33 PM5/6/14
to backbone-...@googlegroups.com
I'm experiencing the same thing with under 100 models... its super fast for a small number of results, but 89 still seems like a small number to be experiencing this sort of thing.

All examples I've seen say to bind sort to the view render. Should this be done differently for better performance?

this.collection.on('sort', this.render(), this);

Guess it could be zombies creeping in, suppose I'll try some explicit unbinding. This may also be your problem as well.
Something like 
this.remove(); this.unbind();
on render()
Reply all
Reply to author
Forward
0 new messages