Skip to content

Preallocate web assembly workers - #1

Merged
belraquib merged 15 commits into
incomingfrom
preallocate-workers
Sep 5, 2019
Merged

belraquib merged 15 commits into
incomingfrom
preallocate-workers

Conversation

@belraquib

Copy link
Copy Markdown
Owner

Optimize end-to-end load time by allowing pthread workers to start loading prior to the webassembly compile step. This is done without a call to onmessage 'load', so these workers aren't ready yet.

This effectively puts the javascript parsing and loading of the workers in a separate thread. Once the webassembly module is loaded, the normal PTHREAD_POOL_SIZE logic kicks in, and greedily uses the preallocated threads.

The test was a little tricky, as the main thread can't join() created threads.

…ly module is compiled. This puts the work of loading and starting up the javascript in parallel with the wasm compile, reducing overall load times.
…u can't join a newly created thread!"

This reverts commit 9ec2778.
…u can't join a newly created thread!"

This reverts commit 9ec2778.

I realized that the issue was with the test  - you can't join() in main() on a thread emscripten might immediately create. This can be fixed in production by proxying the main thread on a pthread, but that would elide giving access to the PThread.foo arrays in the test.
@belraquib
belraquib merged commit 8f5f690 into incoming Sep 5, 2019
belraquib pushed a commit that referenced this pull request Dec 23, 2020
…mscripten-core#8744)

This reverts commit 1d198e4.

Apparently this cause a failure on the mac builder:
https://ci.chromium.org/p/emscripten-releases/builders/ci/mac/b8911649373078606944

```
cache:INFO:  - ok
Traceback (most recent call last):
  File "/b/s/w/ir/k/install/emscripten/emcc.py", line 3391, in <module>
    sys.exit(run(sys.argv))
  File "/b/s/w/ir/k/install/emscripten/emcc.py", line 1894, in run
    final = shared.Building.link(linker_inputs, DEFAULT_FINAL, force_archive_contents=force_archive_contents, just_calculate=just_calculate)
  File "/b/s/w/ir/k/install/emscripten/tools/shared.py", line 1940, in link
    Building.read_link_inputs([x for x in files if not x.startswith('-')])
  File "/b/s/w/ir/k/install/emscripten/tools/shared.py", line 1721, in read_link_inputs
    object_names_in_archives = pool.map(extract_archive_contents, archive_names)
  File "/b/s/w/ir/cipd_bin_packages/lib/python2.7/multiprocessing/pool.py", line 253, in map
    return self.map_async(func, iterable, chunksize).get()
  File "/b/s/w/ir/cipd_bin_packages/lib/python2.7/multiprocessing/pool.py", line 572, in get
    raise self._value
IOError: [Errno 2] No such file or directory: u'/b/s/w/ir/tmp/t/emscripten_temp_oIE5H7_archive_contents/#1/12'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant