• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Summary

To speed execution, optimize your code at the right design level or combination of levels. Start with global optimizations first (for example, algorithm and data structure choices), and then move down toward more local optimizations until your program is fast enough. Refactor to simplify your code, and then minimize DOM interaction and I/O requests. Finally, if all else fails, tune your code locally with the techniques outlined in this chapter. Measure each change, and cool hot spots one at a time. Here is a summary of the optimization techniques discussed in this chapter:

  • Avoid optimization if at all possible.

  • Optimize globally to locally until the code is fast enough.

  • Measure your changes.

  • Keep Pareto in mind.

  • Cool hot spots one at a time.

  • Minimize DOM and I/O interaction (object and property lookups, create and edit subtrees offline).

  • Shorten scope chains to maximize lookup speed. Avoid with statements because they extend scope chains.

  • Cache frequently used values.

  • Simplify loop conditions, hoist loop-invariant code, flip and reverse, and unroll loops with an optimized Duff's Device.

  • Use local optimizations last.

  • Tune expressions for speed.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint