Skip to content

Add option to inline webworker #9796

@VirtualTim

Description

@VirtualTim

Currently when building the USE_PTHREADS Emscripten creates a separate module.worker js file.
This is loaded from module.js like:

var pthreadMainJs = "module.worker.js";
pthreadMainJs = locateFile(pthreadMainJs);
var newWorkers = [];
for (var i = 0; i < numWorkers; ++i) {
  newWorkers.push(new Worker(pthreadMainJs));
}

It is also possible to create an inline webworker, doing something like:

let workerBlob = new Blob(['string_containing_minified_module.worker.js'], type:"application/javascript"});
pthreadMainJs = URL.createObjectURL(workerBlob);
var newWorkers = [];
for (var i = 0; i < numWorkers; ++i) {
  newWorkers.push(new Worker(pthreadMainJs));
}

I imagine that it would be simple enough to minify module.worker.js, then embed that into the main module.js.

I believe that this will speed up loading threads, and should also make webpacking pthreads builds easier/possible.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions