Skip to content

Use worker_threads for running tests#674

Closed
lydell wants to merge 2 commits into
masterfrom
worker_threads
Closed

Use worker_threads for running tests#674
lydell wants to merge 2 commits into
masterfrom
worker_threads

Conversation

@lydell

@lydell lydell commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

This is much simpler, but somehow slower on a big project. I expected it to be faster.

I committed a benchmark. Note: ChatGPT wrote it for me, and I tweaked it. It tests sending messages to and from:

  • worker_threads
  • worker_threads but using JSON.stringify and JSON.parse instead of the regular serialization.
  • child_process.fork with process.send (the built-in IPC communication)
  • child_process.fork with process.send but using JSON.stringify and JSON.parse instead of the regular serialization.
  • child_process.fork with a UNIX pipe like we already use in node-test-runner.

It tests three scenarios:

  • One with real messages recorded from a real elm-test suite, with one test failing (a fuzz test with a distribution report).
  • One with made-up small messages.
  • One with made-up large messages.
❯ node benchmark.js

=== real ===
worker
workerJson
forkIPC
forkIPCJson
socket
┌─────────┬──────────────────────────────┬────────────┬─────────┐
│ (index) │ transport                    │ avgMs      │ totalMs │
├─────────┼──────────────────────────────┼────────────┼─────────┤
│ 0       │ 'worker_threads'             │ '0.164708' │ '24.71' │
│ 1       │ 'worker_threads + JSON'      │ '0.134074' │ '20.11' │
│ 2       │ 'fork + process.send'        │ '0.286465' │ '42.97' │
│ 3       │ 'fork + process.send + JSON' │ '0.272129' │ '40.82' │
│ 4       │ 'fork + UNIX socket'         │ '0.064838' │ '9.73'  │
└─────────┴──────────────────────────────┴────────────┴─────────┘

=== small JSON ===
worker
workerJson
forkIPC
forkIPCJson
socket
┌─────────┬──────────────────────────────┬────────────┬──────────┐
│ (index) │ transport                    │ avgMs      │ totalMs  │
├─────────┼──────────────────────────────┼────────────┼──────────┤
│ 0       │ 'worker_threads'             │ '0.011055' │ '110.55' │
│ 1       │ 'worker_threads + JSON'      │ '0.010293' │ '102.93' │
│ 2       │ 'fork + process.send'        │ '0.017176' │ '171.76' │
│ 3       │ 'fork + process.send + JSON' │ '0.021078' │ '210.78' │
│ 4       │ 'fork + UNIX socket'         │ '0.012623' │ '126.23' │
└─────────┴──────────────────────────────┴────────────┴──────────┘

=== big JSON ===
worker
workerJson
forkIPC
forkIPCJson
socket
┌─────────┬──────────────────────────────┬─────────────┬────────────┐
│ (index) │ transport                    │ avgMs       │ totalMs    │
├─────────┼──────────────────────────────┼─────────────┼────────────┤
│ 0       │ 'worker_threads'             │ '10.392242' │ '10392.24' │
│ 1       │ 'worker_threads + JSON'      │ '7.669622'  │ '7669.62'  │
│ 2       │ 'fork + process.send'        │ '8.023869'  │ '8023.87'  │
│ 3       │ 'fork + process.send + JSON' │ '12.002227' │ '12002.23' │
│ 4       │ 'fork + UNIX socket'         │ '8.824358'  │ '8824.36'  │
└─────────┴──────────────────────────────┴─────────────┴────────────┘
  • For the tests with real messages, the UNIX pipe solution is significantly faster. UNIX sockets/Windows pipes #217 is still true!
  • With the made-up messages, the difference isn’t as big, and UNIX pipe isn’t necessarily the fastest but not the slowest either.

What about worker startup time? worker_threads takes about 35 ms on my machine, while child_process.fork takes about 55 ms. So worker_threads should be slightly faster there. But then the code somehow runs a little bit slower with worker_threads and I haven’t been able to figure out why.

All in all, I don’t think we should switch to worker_threads.

@lydell
lydell force-pushed the worker_threads branch 2 times, most recently from 3ed39e7 to 6f4f556 Compare July 20, 2026 15:39
@lydell lydell closed this Jul 21, 2026
@lydell
lydell deleted the worker_threads branch July 21, 2026 18:01
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