-
Notifications
You must be signed in to change notification settings - Fork 4
JavaScript Cheat Sheet
n8xm edited this page Feb 24, 2018
·
5 revisions
- Module loading can help if loading JS files from a remote server is causing slowdowns. Asynchronous module loading can help reduce latency. (Cozzi ch. 4.2).
- Don't dynamically add properties to objects. (Cozzi ch. 4.3)
-
Object.createis slower than callingnew. 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. (Cozzi ch. 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. (Cozzi ch. 4.3.2)
- GC issues can manifest as a "sawtooth" pattern in a heap usage graph in a profile. (Cozzi fig. 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. (Cozzi listing 4.8)
- Passing large amounts of data between Web Workers can be very slow because by default, they pass by copy. The
Transferableobject helps us avoid this problem. (Cozzi ch. 4.3.3).
- Cozzi, Patrick et al. WebGL Insights.