-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lazy render list, 10 at a time #477
Conversation
@zmbc @Lukeswart -- I played around with this branch on the raingardens flavor--the scroll-to-bottom feature works well. I'm starting to think there are at least two culprits behind the raingarden flavor's slowness, though. One is definitely rendering: as models are added to the list view's collection, a But another issue (and one that I think has a bigger impact on performance, at least based on some rough testing) is that the list view sorts all places every time the So I think we'll need to both lazily render and lazily sort for performance to improve. One possibly easy way to do this is maintain two collections in the list view: the existing collection (which accumulates references to all place models on the map as they are retrieved from the server), and another "working" collection, to which we could feed batches of 10 or so models as the user scrolls to the bottom of the list view. We would render and sort the working collection only. I dunno--does that sounds reasonable? Maybe it's kind of sloppy to have multiple collections for the same models lying around. |
I guess one problem with the above approach is that sorting would no longer act on the full collection. So if you wanted to see, say, the raingarden with the most likes in the whole set, you wouldn't be able to. There might be other things we can do to speed up sorting. I found this discussion: It suggests passing a It seems that collections with a comparator function defined will sort themselves after each model is added by default, unless |
Because I don't really know enough to rip out Marionette completely, I went for the more moderate approach, similar to the one you mentioned (using 2 different collections). Code reviews very much welcome. I don't think I broke anything about the list view. As far as the two goals of this PR:
I think this PR is feature-complete (the |
@zmbc -- this looks great! I was actually thinking that the two-collection approach might be toast because I wasn't sure how you'd manage sorting on the full collection, but I think I see how you got around that issue: passing models between the two collections as needed to facilitate sorting and searching. Nice. There's a very noticeable performance boost on my laptop. I find that if I also pass a @Lukeswart -- what do you think about this two-collection approach? I think in the past you mentioned that having models in multiple collections could be dicey, but it seems to me that if we keep everything isolated in the list view it should be ok? |
@zmbc Nice work! This looks great. I think we should merge this in soon. This approach using multiple collections seems reasonable. @goldpbear Thanks for looking into the sorting aspects of this issue. After a few performance tests, it looks like it saves ~15 seconds of script time, so I think we should go for it! The downside is that the rendered list won't stay sorted as places are updated or added in real time. But I think it's worth the tradeoff because the performance gain is very significant when we have thousands of places, and the user can always close/re-open the list view to view a re-sorted list. Once this issue is addressed, I suspect that the remaining performance issues are due to #264. I've attached some metrics on the raingardens flavor if anyone is interested: |
this.collection.sort(); | ||
this.unrenderedItems.sort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if we want to merge the models in this.collection
into this.unrenderedItems
(similar to what happens below on lines 257-258) here before sorting, then just sort this.unrenderedItems
. If not, aren't we sorting the two collections separately, and, when we merge them on lines 257-258, then iterating through a collection that isn't completely sorted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, actually it might not matter--I think that since the default behavior of .add()
is to sort models as they are added to a collection, the call to this.unrenderedItems.add(this.collection.models)
on line 257 should be sorting unrenderedItems
. But in that case the call to this.collection.sort()
on line 235 might be unnecessary?
FYI, there seems to be an issue on this branch where certain list view items refuse to render their support views (the "like" buttons that appear at right). Some will render, and some won't. As you scroll down through the list and lazily load more items, previously un-rendered support views will suddenly appear, but the occasional newly-rendered list item will be missing its support view. I think I found a solution to this: call |
Need to test on Raingardens flavor! I have a feeling there might be other bottlenecks on that flavor, but this at least eliminates one of them.
#451