PSA: Emscripten will no longer generate a separate worker.js file in pthreads mode.

34 views
Skip to first unread message

Sam Clegg

unread,
Apr 16, 2024, 3:36:29 PMApr 16
to emscripte...@googlegroups.com
;TLDR; If you build/deploy pthread-based programs you no longer need to worry about that extra `.worker.js` file.

I'm hoping to land this change today which is fairly large internal change to the pthread workers are bootstapped: https://github.com/emscripten-core/emscripten/pull/21701

The main externally visible change is that emscripten will no longer depend on a separate `.worker.js` file to start the pthread workers.

This means that build and deployment system will need to be updated to account for the lack of this file.  It's one less file to deal with so it should be a simplification in all cases.   For a tran sition period (I imagine a few releases) emscripten will continue to generate an empty `.worker.js` (unless you build with `-sSTRICT`) to give folks some time to transition away from deploying the `.worker.js` file.

cheers,
sam

Brooke Vibber

unread,
Apr 25, 2024, 12:06:32 PMApr 25
to emscripte...@googlegroups.com
I had a problem updating my ogv.js codec shims to use 3.1.58 with the new pthreads output, I'll try tracking down exactly what was going wrong but it seems like the path to the main .js wasn't getted transmitted correctly through to the worker loader and it would just 404 out with a bad path.

Once I get a chance to test in more detail it's probably something sensible, but it didn't work as just a drop-in upgrade vs 3.1.57.

-- brooke

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAL_va2_jh9eYSYfJz8NDQhjOvTf4wjku1YO6K1Du6fusAnVgGA%40mail.gmail.com.

Brooke Vibber

unread,
Apr 25, 2024, 1:22:34 PMApr 25
to emscripte...@googlegroups.com
Figured it out -- my code had been setting Module.mainScriptUrlOrBlob without the relative path set, which somehow didn't cause any problems before :D but definitely caused loading the wrong URL (without subdirectory) with 3.1.58 when launching a worker.

(Possibly this was due to loading the _worker thread helper js_ with the right URL and then passing it the _local path to the main file_ which, relative to the worker, was in the same directory so a bare path was fine. If you weren't fiddling with this setting to host things in a subdirectory before, you probably won't have trouble.)

After setting this correctly to include the relative path, it seems happier and I have a functioning VP9 codec in pthread build too. :D

Huzzah!

-- brooke

Sam Clegg

unread,
Apr 25, 2024, 1:34:48 PMApr 25
to emscripte...@googlegroups.com
Glad you figured it out.   We do have two other folks how are having similar issue:


I have a fix one fix out that should help in some cases (specifically folks how use locateFile): https://github.com/emscripten-core/emscripten/pull/21829.   Does this look like it would help in your case?

On Thu, Apr 25, 2024 at 10:22 AM Brooke Vibber <br...@pobox.com> wrote:
Figured it out -- my code had been setting Module.mainScriptUrlOrBlob without the relative path set, which somehow didn't cause any problems before :D but definitely caused loading the wrong URL (without subdirectory) with 3.1.58 when launching a worker.

I'm curious if `mainScriptUrlOrBlob` is still needed for you use case?  With the new setup I think there are fewer cases where it is needed.

Brooke Vibber

unread,
Apr 25, 2024, 3:14:29 PMApr 25
to emscripten Mailing List
On Thu, Apr 25, 2024, 10:34 AM 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
Glad you figured it out.   We do have two other folks how are having similar issue:


I have a fix one fix out that should help in some cases (specifically folks how use locateFile): https://github.com/emscripten-core/emscripten/pull/21829.   Does this look like it would help in your case?

It had no trouble finding the wasm binary for me, just with finding the JavaScript in the worker, which was because I was specifically giving it a wrong path in Module['mainScriptUrlOrBlob'] I think because that's what the prior behavior wanted because it loaded it in the worker's context, where the base URL for the main JS, worker JS, and binary were all in the same subdirectory.

-- brooke
 

Sam Clegg

unread,
Apr 25, 2024, 4:31:10 PMApr 25
to emscripte...@googlegroups.com
On Thu, Apr 25, 2024 at 12:14 PM Brooke Vibber <br...@pobox.com> wrote:
On Thu, Apr 25, 2024, 10:34 AM 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
Glad you figured it out.   We do have two other folks how are having similar issue:


I have a fix one fix out that should help in some cases (specifically folks how use locateFile): https://github.com/emscripten-core/emscripten/pull/21829.   Does this look like it would help in your case?

It had no trouble finding the wasm binary for me, just with finding the JavaScript in the worker, which was because I was specifically giving it a wrong path in Module['mainScriptUrlOrBlob'] I think because that's what the prior behavior wanted because it loaded it in the worker's context, where the base URL for the main JS, worker JS, and binary were all in the same subdirectory.

Can you confirm if you are now able to completely remove your usage of `mainScriptUrlOrBlob`?  I'm hoping the number of cases where this is needed is now almost zero.

cheers,
sam

Brooke Vibber

unread,
Apr 25, 2024, 4:50:06 PMApr 25
to emscripte...@googlegroups.com
On Thu, Apr 25, 2024 at 1:31 PM 'Sam Clegg' via emscripten-discuss <emscripte...@googlegroups.com> wrote:
Can you confirm if you are now able to completely remove your usage of `mainScriptUrlOrBlob`?  I'm hoping the number of cases where this is needed is now almost zero.

Yes, maiScriptUrlOrBlob is not required to be set in 3.1.58 for me; simply leaving it unset works fine.

-- brooke
Reply all
Reply to author
Forward
0 new messages