Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualsmr

Posted 04 January 2013 - 03:58 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls to JavaScript are expensive. Calls to built-in functions may or may not be.
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • Consider dictionary.thing to be equivalent to dictionary['thing'] as far as performance is concerned.
  • Functions are first class objects, and being first class objects they are no different than any other element in a dictionary on your objects: This line: "myobject.function()" can be considered the equivalent of "myobject['function']()" as far as efficiency goes. You can hoist this outside the loop too: 
    var myobject = new MyObject(whatever);
    var hoisted = myobject.function;
    
    for (var i = 0; i < 1000; ++i) {
        for (var j = 0; j < 1000; ++j) {
            hoisted(i, j);
        }
    }

     

     

  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • Use built-in functions whenever possible, because they're often implemented in a low level language and compiled to machine code.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.

#5smr

Posted 04 January 2013 - 03:56 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls to JavaScript are expensive. Calls to built-in functions may or may not be.
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • Consider dictionary.thing to be equivalent to dictionary['thing'] as far as performance is concerned.
  • Functions are first class objects, and being first class objects they are no different than any other element in a dictionary on your objects: This line: "myobject.function()" can be considered the equivalent of "myobject['function']()" as far as efficiency goes. You can hoist this outside the loop too: 
    var myobject = new MyObject(whatever);
    var hoisted = myobject.function;
    
    for (var i = 0; i < 1000; ++i) {
        for (var j = 0; j < 1000; ++j) {
            hoisted(i, j);
        }
    }

     

     

  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.

#4smr

Posted 04 January 2013 - 03:54 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls to JavaScript are expensive. Calls to built-in functions may or may not be.
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • Consider dictionary.thing to be equivalent to dictionary['thing'] as far as performance is concerned.
  • Functions are first class objects, and being first class objects they are no different than any other element in a dictionary on your objects: This line: "myobject.function()" can be considered the equivalent of "myobject['function']()" as far as efficiency goes. You can hoist this outside the loop too: 
    var myobject = new MyObject(whatever);
    var hoisted = myobject.function;
    
    for (var i = 0; i < 1000; ++i) {
        for (var j = 0; j < 1000; ++j) {
            hoisted.apply(this, i, j);
        }
    }

     

     

  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.

#3smr

Posted 04 January 2013 - 03:51 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls to JavaScript are expensive. Calls to built-in functions may or may not be.
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • Consider dictionary.thing to be equivalent to dictionary['thing'] as far as performance is concerned.
  • Functions are first class objects, and being first class objects they are no different than any other element in a dictionary on your objects: This line: "myobject.function()" can be considered the equivalent of "myobject['function']()" as far as efficiency goes. You can hoist this outside the loop too: 
    var myobject = new MyObject(whatever);
    
    var hoisted = function (i, j) {
        return myobject.function(i, j);
    }
    
    for (var i = 0; i < 1000; ++i) {
        for (var j = 0; j < 1000; ++j) {
            hoisted(i, j);
        }
    }

     

     

  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.

#2smr

Posted 04 January 2013 - 03:46 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls to JavaScript are expensive. Calls to built-in functions may or may not be.
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.

#1smr

Posted 04 January 2013 - 03:44 PM

First and foremost, since JavaScript is a programming language, the same general rules apply to writing efficient code:

  • Use the best algorithm for the task. Example, don't spend hours optimizing your bubble sort procedure when a quicksort will always be faster.
  • Use the features provided by the language's standard library, because they're probably written better than anything you'll create. Example, don't write your own quicksort. The standard library sort probably already does it.

Since javascript is a dynamic language, most of the same rules apply when optimizing:

  • Function calls are expensive
  • Dictionary references are expensive. Example: dictionary['thing']. If you need to access the same element more than once in a loop, assign it to a local variable before the loop then reference it with the variable.
  • "for (var i = 0; i < arrayLength; ++i)" is more efficient than "for (var i in array)" or even "for (var i = 0; i < array.length; ++i)" when the dictionary can be indexed sequentially.
  • jsPerf is a great resource.
  • Don't optimize until you've profiled.
  • What is fast in Chrome might be slow in Safari, Firefox or Internet Explorer.

PARTNERS