Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7872297
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:09:44+00:00 2026-06-03T02:09:44+00:00

I upgraded from 0.5.3 to 0.9.2 of backbone.js and I noticed a significant decrease

  • 0

I upgraded from 0.5.3 to 0.9.2 of backbone.js and I noticed a significant decrease in speed on my application. The application handles many large collections and adds a large number of models at certain points. There is anywhere between 0 to 600 models added at a time. In the 0.5.3 version the sortedIndex function was the most used taking 12% of the CPU. in the 0.9.2 version the code became significantly slower and the sortBy function was taking 70% of the CPU.

I suspect that they are adding all the models then sorting it rather than adding each model to where it should be to keep the collection sorted. Is there a flag I can use to make it use the old method or any other way of speeding it up. I realise that I could implement my own collection class specific for my large data sets but I would prefer to stick with backbone collections right now.

Here is the collection comparator

comparator: function(model) {
    return model.get("timestamp");
}

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:09:45+00:00Added an answer on June 3, 2026 at 2:09 am

    You could try using a two-argument comparator:

    Comparator function can be defined as either a sortBy (pass a function that takes a single argument), or as a sort (pass a comparator function that expects two arguments).

    so that you could use the native sort rather than Underscore’s sortBy; sortBy has a bit of overhead from the _.pluck and _.map calls and from building the objects for the Schwartzian Transform; a Schwartzian Transform really only makes sense when computing the sort keys is expensive, m.get(a) is not expensive and m.attributes[a] (which is all get does anyway) is cheaper still.

    So an easy first attempt would be:

    comparator: function(a, b) {
        if(a.attributes.timestamp < b.attributes.timestamp)
            return -1;
        else if(a.attributes.timestamp > b.attributes.timestamp)
            return 1;
        return 0;
    }
    

    The Collection#add method does sort the collection on each insertion:

    for (i = 0, length = models.length; i < length; i++) {
      //...
      if (this.comparator && options.at == null) this.sort({silent: true});
      //...
    }
    

    unless you tell it where to put the models using the at option; the "add" event includes the index of the newly added element so the collection needs to sort on each insertion so that the event has the right values. But, if you can pre-sort the models before calling add and find the correct insertion point manually, then you can skip the sort calls inside add. You might have to add your models one-by-one of course but that shouldn’t be difficult: just walk through both the new (pre-sorted) models and the existing collection concurrently to figure out the correct insertion point for each model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently upgraded from Grails 1.3.7 to Grails 2.0.1. The application runs normal, but
I just upgraded from Dojo 1.4.3 to 1.5.0 and noticed that my legend is
Recently a software application we utilize upgraded from ASP to ASP.NET. In the process
I recently upgraded from 4.0.1 to 4.2.1 and noticed that when I publish to
We just recently upgraded from VS2005 to VS2010. I've noticed that unlike VS2005, when
I'm trying to publish a Rails 3.1 (upgraded from 3.0) application. After submitting the
I upgraded from Chrome version 17 to Chrome: 18.0.1025.142 today. I've noticed one of
I upgraded from MacOS X 10.6 (Snow Leopard) to 10.7 (Lion) this morning, and
I recently upgraded from jQuery 1.2.6 to 1.3.2 Now on the page I'm using
I've just upgraded from MRI-1.8.7 to MRI-1.9.1 and heard about this lighthouse ticket which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.