WebAssembly / WebAssembly/binaryen

Reduce threading overhead

Open
#2,740 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
WebAssembly
Stars
8.6k
Forks
885
Avg merge
1d 19h
Merged PRs (30d)
69

Description

Our threading overhead seems significant. When I measure a fixed pure computational workload, replacing the body of a pass like precompute to instead just do some silly work, then measuring with time, the user time is the same when BINARYEN_CORES=1 (use 1 core) and when running normally with all cores. That makes sense since the total actual work is added up in user, and it's the same. And there isn't much synchronization overhead that slows us down.

But that's not the typical case when running real passes, the user for multi-core can be much higher, see e.g. https://github.com/WebAssembly/binaryen/pull/2733#issuecomment-611246791 and I see similar things locally with user being 2-3 larger when using 8 threads.

This may be a large speedup opportunity. One possibility is that we often have many tiny functions, and maybe switching between them is costly? Or maybe there is contention on locks (see that last link, but this happens even after that PR which should get rid of that).

The thread-pool using code for running passes on functions is here: https://github.com/WebAssembly/binaryen/blob/dc5a503c4d54dc71ab46535c1966540785562dd7/src/passes/pass.cpp#L591

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the thread-pool code in src/passes/pass.cpp around line 591. Reproduce the fixed pure-computational workload comparison using BINARYEN_CORES=1 and the normal multi-core configuration, then measure user time for real passes. Done means identifying the source of excess multi-threaded overhead and demonstrating a reduction with measurements.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, wasm
Domain
compilers, performance
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.