Skip to content

Instantly share code, notes, and snippets.

@mteece
Created December 10, 2012 16:03
Show Gist options
  • Select an option

  • Save mteece/4251481 to your computer and use it in GitHub Desktop.

Select an option

Save mteece/4251481 to your computer and use it in GitHub Desktop.
Cache the array length to speed up for loop. Preassign the array length instead of testing it again in every step.
/* //Below code is causing the slowdown
for (var i = 0; i < records.length; i++) {
var record = new recordTemplate(records[i]);
this.store.add(record);
}
},
*/
// Better code
var records2 = [];
var recLength = records.length;
for (var i = 0; i < recLength; i++) {
records2.push(new recordTemplate(records[i]));
}
this.store.insert(0, records2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment