Skip to content

Instantly share code, notes, and snippets.

@pawel-dubiel
Created September 29, 2012 01:52
Show Gist options
  • Save pawel-dubiel/3802890 to your computer and use it in GitHub Desktop.
Save pawel-dubiel/3802890 to your computer and use it in GitHub Desktop.
Javascript optimisation
Some quick notes from http://www.youtube.com/watch?v=UJPdhx5zTaw
Don't mix types ( be sure the array is only of one type )
Don't read out of bounds
Avoid operations with undefined values ( always initialize )
Don't add a new properties to the object during runtime
Initialize all object members in constructor functions
Always initialize object members in the same order
Use 31 bit signed numbers in critical calculations
Don't preallocate arrays elements
Don't delete elements from arrays
Don't load from uninitialized or deleted elements.
Avoid dom operations.
Avoid types conversion.
Wrong:
var a = new Array();
a[0] = 22 //allocates
a[1] = 42
a[2] = 0.5 //allocates,converts
a[3] = true //allocates,converts
Right way:
var a = [ 22, 42, 0.5, true ];
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment