Tutorial by Examples

Some JavaScript engines (for example, the current version of Node.js and older versions of Chrome before Ignition+turbofan) don't run the optimizer on functions that contain a try/catch block. If you need to handle exceptions in performance-critical code, it can be faster in some cases to keep the ...
If you are building a function that may be heavy on the processor (either clientside or serverside) you may want to consider a memoizer which is a cache of previous function executions and their returned values. This allows you to check if the parameters of a function were passed before. Remember, p...
Most performance tips are very dependent of the current state of JS engines and are expected to be only relevant at a given time. The fundamental law of performance optimization is that you must first measure before trying to optimize, and measure again after a presumed optimization. To measure cod...
Javascript engines first look for variables within the local scope before extending their search to larger scopes. If the variable is an indexed value in an array, or an attribute in an associative array, it will first look for the parent array before it finds the contents. This has implications wh...
Example A var i,a,b,len; a = {x:0,y:0} function test(){ // return object created each call return {x:0,y:0}; } function test1(a){ // return object supplied a.x=0; a.y=0; return a; } for(i = 0; i < 100; i ++){ // Loop A b = test(); } for(i = 0; i < 100; ...
A common mistake seen in JavaScript when run in a browser environment is updating the DOM more often than necessary. The issue here is that every update in the DOM interface causes the browser to re-render the screen. If an update changes the layout of an element in the page, the entire page layout...
All modern JavaScript JIT compilers trying to optimize code based on expected object structures. Some tip from mdn. Fortunately, the objects and properties are often "predictable", and in such cases their underlying structure can also be predictable. JITs can rely on this to make pred...
If the engine is able to correctly predict you're using a specific small type for your values, it will be able to optimize the executed code. In this example, we'll use this trivial function summing the elements of an array and outputting the time it took: // summing properties var sum = (functio...

Page 1 of 1