Skip to content

JavaScript Cheat Sheet

n8xm edited this page Feb 24, 2018 · 5 revisions

Performance Tips

  • Module loading can help if loading JS files from a remote server is causing slowdowns. Asynchronous module loading can help reduce latency. (WebGL Insights Chapter 4.2).
  • Don't dynamically add properties to objects.
  • Object.create is slower than calling new. Object literal notation is almost as fast as new, as long as functions are cached in a parent scope to avoid re-creating the functions every time we create an object. (WebGL Insights Chapter 4.3.1).
  • Computing intermediate values that are quickly thrown away (e.g. vec3 object for linear algebra math) causes problems because unlike with other languages like C++ they don't live on the stack. Therefore, they can incur significant garbage collection overhead. (WebGL Insights Chapter 4.3.2)
    • GC issues can manifest as a "sawtooth" pattern in a heap usage graph in a profile. (WebGL Insights Figure 4.2)
    • Avoid these issues by having users pass in already-allocated result parameters, and using module-scoped scratch parameters to reduce the number of allocations. (WebGL Insights Listing 4.8)
  • Passing large amounts of data between Web Workers can be very slow because by default, they pass by copy. The Transferable object helps us avoid this problem. (WebGL Insights Chapter 4.3.3).

Clone this wiki locally