Hacker News new | ask | show | jobs
by wyuenho 4766 days ago
Backbone's View is incredibly slow and is very ill-suited for views that need 1000+ of them on a single page. The reason is not so much Backbone's code is particularly inefficient but the fact that Backbone.View creates a separate a jQuery context in its constructor, and then delegates events in it, also using jQuery. Both are among the slowest parts of jQuery because they have to go thru Sizzle. So if you have 1000+ of Views, each creating a separate jQuery context of its own, you can easily run up to taking seconds to render a page on Mobile.

On Backgrid (my project), naively creating 1200+ view objects on a Macbook Pro on a 2.4gz i7 takes 700ms. It really does take seconds on mobile.

I'm in the process of getting rid of jQuery and coming up with a performant View class that works more or less like Backbone.View but uses the DOM API directly. Implementing event delegation with straight DOM methods have proven to be troublesome and unreliable so I might need to come up with a different way to attach event handlers on a DOM tree.