BackgroundWorker html5 delays

Hi all, thanks for making OpenFL great.

I have a little problem I can’t seem to solve using the lime.system.BackgroundWorker.

I’m compiling to HTML5 and I am able to query and load dynamic image resources from the host domain without any issues.

But, when I use a background worker to decode the loaded data I get a huge delay and massive drops in frame rate. It seems that the background worker is running on the browsers main thread.

var worker: BackgroundWorker = new BackgroundWorker();

	worker.doWork.add(function(_) {
		log.info("Start - texture decode");
		var bitmapData: BitmapData = BitmapData.fromBytes(loader.data);
		log.info("End - texture decode");
		worker.sendComplete();
	});
	worker.onComplete.add(function(_) { ... });

	worker.run();

This is the offending chunk of code, I’ve enabled timestamps on my console window and can confirm that the huge delays are right between the 2 log lines I added. I do repeat this for ~40 - 50 times and I wait until each image is fully loaded and ready before starting the request to load the next image.

I tried looking through the docs for the BackgroundWorker, but they are sparse, and seem to indicate that it should work for the html5 target.

Any ideas or suggestions would be most welcome.

Thank you

The Lime BackgroundWorker falls back to a synchronous approach on platforms that do no support threads. However, most modern browsers support JS workers. This is just a matter of being implemented.

If you’re interested in taking a look, adding JS worker support would be great, and would obviously help with your use-case:

Hi @singmajesty , thanks for the quick response.

I’ll see what I can do, although it doesn’t seem like we’d be able to pass graphics processing to a worker, since (based on a rudimentary understanding of the spec) there’s no neat way to return the created BitmapData object to the calling process.

I’ve found a great library which enables worker functionality for js - https://github.com/Rezmason/Golems

Thanks for all the help
Regards

You cannot pass a canvas object or canvas context to a worker thread because the canvas is part of the DOM.

However, you can use bitmapData.getPixels, then process the pixel array, then bitmapData.setPixels after the worker is finished