"Performance" usually does not mean how fast your script runs. There are also many other important factors, such as how quickly your computer freezes and / or crashes. Memory. The smallest javascript implementation in memory, usually allocated to var, is 32 bits. It means
var a = true;
in your memory looks like this:
0000 0000 0000 0000 0000 0000 0000 0001
This is a huge waste, but usually this is not a problem, since no one uses a significant enough number of them to really make a difference. Typed arrays are designed for cases where it matters, when you can actually reduce the amount of memory used by a huge amount, for example, when working with image data, audio data, or all kinds of raw binary data.
Another difference, which in some cases can potentially save even more memory, is that it allows you to work with data passed by reference, which you usually pass by value.
Consider this case:
var oneImage = new Uint8Array( 16 * 16 * 4 ); var onePixel = new Uint8Array( oneImage.buffer, 0, 4 );
now you have 2 independent views on the same ArrayBuffer array working on the same data, applying this concept not only allows you to have one huge thing in your memory, but also allows you to divide it into as many segments as you currently want to work with little overhead, which is probably even more important.
Winchestro
source share