Skip to content

Run spec tests in parallel to reduce the execution time#8088

Merged
stevenfontanella merged 8 commits into
mainfrom
multithread
Dec 5, 2025
Merged

Run spec tests in parallel to reduce the execution time#8088
stevenfontanella merged 8 commits into
mainfrom
multithread

Conversation

@stevenfontanella
Copy link
Copy Markdown
Member

@stevenfontanella stevenfontanella commented Dec 3, 2025

Reduces runtime from ~15 minutes to 1.5 minutes on my machine

Before:
image

After:
image

Failed test example (stdout and stderr isn't ordered with the exception unfortunately, but it's easy to re-run the particular test):
image

  • Run tests through a thread pool with os.cpu_count() * 2 threads
    • os.cpu_count() * 4 shows no benefit. os.cpu_count() or os.cpu_count() // 2 also show no regression in runtime, but might be worse for machines with less cores. There are currently 315 spec tests total for reference.
  • Prefixes round-trip file name tests with their test name to avoid clobbering the a.wasm / ab.wast files during tests
  • Add stdout and stderr params to functions that print so that lines can be captured by each thread and not interleaved
    • Note that we pass stdout as the stderr param in practice so that they are interleaved, otherwise all stdout lines and stderr lines will be outputted together in each test.

@stevenfontanella stevenfontanella force-pushed the multithread branch 3 times, most recently from 44c5834 to 62b613b Compare December 4, 2025 01:19
@stevenfontanella stevenfontanella changed the title Add multithreading for spec tests Run spec tests in parallel to reduce the execution time Dec 4, 2025
@stevenfontanella stevenfontanella marked this pull request as ready for review December 4, 2025 01:56
@tlively
Copy link
Copy Markdown
Member

tlively commented Dec 4, 2025

The alpine builder has been running for over three hours now, so I think there's a problem here. Looking at the log, it looks much more verbose than before because the stdout from the wasm-shell commands is being printed. Maybe fixing that will make the builder go faster?

Comment thread scripts/test/support.py Outdated
Comment thread check.py Outdated
Comment thread check.py Outdated
Comment thread check.py Outdated
Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Comment thread check.py
Comment thread check.py Outdated
Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % open comments

Comment thread check.py Outdated
@stevenfontanella
Copy link
Copy Markdown
Member Author

Re:

The alpine builder has been running for over three hours now, so I think there's a problem here. Looking at the log, it looks much more verbose than before because the stdout from the wasm-shell commands is being printed. Maybe fixing that will make the builder go faster?

I changed support.run_command to not print the process's stdout and fixed the Alpine build (it's using a lower Python version and didn't have Queue.shutdown())

@stevenfontanella
Copy link
Copy Markdown
Member Author

I think the CI problem is that this member isn't initialized in the default constructor of SmallVector since std::array is an aggregate type. I'm not sure why we see the breakage here and not in main or in other architectures. I'll try to re-run for now and send a PR to fix separately.

CI link

@kripken
Copy link
Copy Markdown
Member

kripken commented Dec 5, 2025

About the std::array initialization error, we do disable that warning a few lines above for some archs, and maybe we just need to disable it in more. gcc does seem to have many such false positives...

Comment thread src/support/small_vector.h
@stevenfontanella stevenfontanella enabled auto-merge (squash) December 5, 2025 20:40
@stevenfontanella stevenfontanella merged commit 28e849b into main Dec 5, 2025
17 checks passed
@stevenfontanella stevenfontanella deleted the multithread branch December 5, 2025 21:10
kripken pushed a commit to kripken/binaryen that referenced this pull request Dec 10, 2025
…8088)

Reduces runtime from ~15 minutes to 1.5 minutes on my machine

* Run tests through a thread pool with `os.cpu_count()` threads
* `os.cpu_count() * 4` shows no benefit. `os.cpu_count() // 2` also shows
no regression in runtime, but might be
worse for machines with less cores. There are currently 315 spec tests
total for reference.
* Prefixes round-trip file name tests with their test name to avoid
clobbering the a.wasm / ab.wast files during tests
* Add stdout and stderr params to functions that print so that lines can
be captured by each thread and not interleaved
* Note that we pass stdout as the stderr param in practice so that they
are interleaved, otherwise all stdout lines and stderr lines will be
outputted together in each test.
Copy link
Copy Markdown
Member

@sbc100 sbc100 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just came here to say things change is awesome. Why didn't we do this earlier!

Comment thread scripts/test/support.py
# Hack to allow subprocess.Popen with stdout/stderr to StringIO, which doesn't have a fileno and doesn't work otherwise
def _process_communicate(*args, **kwargs):
overwrite_stderr = "stderr" in kwargs and isinstance(kwargs["stderr"], io.StringIO)
overwrite_stdout = "stdout" in kwargs and isinstance(kwargs["stdout"], io.StringIO)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ha, this looks very similar to the code we have in emscripten test suite for this same purpose: https://github.com/emscripten-core/emscripten/blob/cb4450380c27e9be81e7c239ec7af5005ad283cd/test/common.py#L1153-L1181

Great minds think alike (or use the same AI :)

@stevenfontanella
Copy link
Copy Markdown
Member Author

Thank you Sam!

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.

4 participants