JSFiddle - React, Tailwind, and code Playground
HTML
<div id='log'></div>
<script id="worker" type="text/js-worker">
addEventListener("message", function (e) {
//var data = e.data;
postMessage({
message: "worker started"
});
});
</script>
JavaScript
// worker embedded for jsfiddle
var blob = new Blob(Array.prototype.map.call(document.querySelectorAll("script[type=\"text\/js-worker\"]"), function (oScript) { return oScript.textContent; }),{type: "text/javascript"});
var worker = new Worker(window.URL.createObjectURL(blob));
worker.addEventListener("message", function (e) {
log(e.data.message);
});
// build the data and start the worker
function go() {
log("building data");
var data = buildData();
log("starting worker");
worker.postMessage({
command: "start",
data: data
});
}
// here we build up the data to about the same size as when it fails
function buildData() {
var max = 1000; // <----------------------------- Chanage this to 15000 to see failure
var data = [];
for (var i = 0; i < max; i++)
data.push(new MyClass(i));
return data;
}
// mimic one of the product classes in use at the time the failure occurred.
// this does not seem to cause the problem (leaving it out didn't help)
function MyInnerClass() {
this.a = -Math.random() * 1000;
this.b = -Math.random() * 1000;
this.c = -Math.random() * 1000;
this.d = Math.random() * 1000;
this.e = Math.random() * 1000;
this.f = Math.random() * 1000;
}
// this class has the same structure as the production code
// that exhibits the web worker bug. The main problems are
// with large array buffers. Not sure why Chrome can't seem
// to post this data to the web worker when the array buffers
// are larger (7000-45000 elements).
function MyClass(id) {
var count32 = getRandomSize();
var count16 = count32 * 3;
this.uint16 = new Uint16Array(count16);
this.float32_a = new Float32Array(count32);
this.float32_b = new Float32Array(count32);
for (var i = 0; i < count16; i++)
this.uint16[i] = i;
for (var i = 0; i < count32; i++) {
this.float32_a[i] = i * Math.random();
this.float32_b[i] = i *...