I have an application that generates a lot of data. This data needs to be processed before it's usable (WebGL 3D application). So I created a web worker to do the processing to keep from blocking the rest of the UI.
The problem is that when the data is large enough, the very first call to start the web worker causes the tab in Chrome to crash and display the "Aw, Snap" message. I've set breakpoints at the very beginning of the web worker, and it doesn't even make into the web worker. It seems to crash while trying to clone the data for the postMessage() call.
Here is the general data structure (trying to pass an array of these to a web worker):
function MyClass(id) {
var count32 = getSize();
var count16 = count32 * 3;
this.uint16 = new Uint16Array(count16); // array buffer 1
this.float32_a = new Float32Array(count32); // array buffer 2
this.float32_b = new Float32Array(count32); // array buffer 3
this.a = id;
this.b = count32;
this.c = new MyInnerClass();
this.d = true;
this.e = 6;
this.f = {a: 1, b: 2, c: 3, d: 4};
this.g = [];
}
function MyInnerClass() {
this.a = -10;
this.b = -20;
this.c = -30;
this.d = 10
this.e = 20
this.f = 30
}
The problem is with array buffers 1, 2 and 3. I have an array of MyClass objects, about 15,000, and about 97% of the array buffers have fewer than 200 elements. But for the remaining 3%, the array buffers have anywhere from 1,000 to 40,000 elements.
Interestingly, if I comment out any 2 of the array buffers, the postMessage() containing the classes will work.
Another interesting point: if I click the "Pause on startup" checkbox in the dev tools in Chrome, the postMessage() will sometimes work, even with all 3 array buffers. Otherwise, it will fail everytime.
Anyone know why this is occurring? I couldn't find docs on the constraints of the data that I might be hitting, or other strange internal weirdness. Otherwise, I'm gonna end up refactoring my code quite a bit to get around this.
DEMO: I created a jsfiddle to demonstrate this: http://jsfiddle.net/GmvyJ/11/
If you change the data max size in this fiddle (to 15,000), please don't save it that way, otherwise you'll never be able to reach the page anymore.