Know Your Engines: How to Make Your JavaScript Fast

The main part of the talk will explain how each major JavaScript language feature is compiled and run, how fast it is compared to other operations, and what “performance faults” can make it much slower than expected. For example, reading a property (x = o.p) is implemented by compiling a bit of code to get the property value very quickly for any object with the same properties. This means that if a given line of code reads a property always from objects that look the same, it is very fast; if it works on objects with different property sets, it is usually still fast; if it works on objects that don’t have that property, it will be very slow. I will avoid details that are interesting mainly to engine implementers in favor of giving concrete, intuitive models that developers can use to predict performance and understand performance problems.

In the second, shorter part, I’ll talk about current and future work to make JavaScript go faster, and what it might mean for developers. One area is advanced research-derived optimizations, such as tracing (TraceMonkey), dynamic type profiling (Crankshaft), and type inference. These technologies have the potential to dramatically speed up programs, but they will probably work much better on programs where values usually have the same type, so developers should know something about what kinds of programs benefit. Another area is simpler, more practical additions, such as web worker threads, which enable multithreading in browser JavaScript, and typed arrays, which allow fast computation on arrays of integers, including pixel data. The main goal of this part of the talk is to give developers ideas about what new things may be possible in JavaScript in the near future.