title: WebSocket frequent onmessage zero-copy
body: <p>I have an app that receives binary messages over a WebSocket frequently (at least once per frame) and plots the data, using canvas/webgl. I've noticed that I have a pretty good saw-tooth memory profile; lots of short lived chunks of data.
  <a href="https://i.stack.imgur.com/Vp3Us.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Vp3Us.png" alt="enter image description here"></a></p>
  
  <p>This does not surprise me since I'm receiving an object from <code>onmessage</code>, at least once every 16ms, which is used for drawing and then de-referenced.</p>
  
  <p>My question is: are there any tips for avoiding/minimizing this? Based on the <a href="https://developer.mozilla.org/en-US/docs/Web/API/WebSocket" rel="noreferrer">WebSocket API</a>, there doesn't seem to be an alternative to having new memory allocated on every socket receive call. In another language/environment, I'd pre-allocate some memory and receive into that buffer, to avoid constantly allocating memory for short lived objects, but I can't think of any obvious way to achieve this in JavaScript in the browser.</p>
  
  <p>For reference, here is my Frames view.</p>
  
  <p><a href="https://i.stack.imgur.com/snx7c.png" rel="noreferrer"><img src="https://i.stack.imgur.com/snx7c.png" alt="enter image description here"></a> </p>
  
  <p>I don't know if that idle time is garbage collection? Any dev-tools ninja insights would be greatly appreciated.</p>