Skip to content

perf: compile wasm plugin functions in parallel - #1315

Merged
dsherret merged 2 commits into
mainfrom
perf-parallel-wasm-compile
Oct 10, 2026
Merged

dsherret merged 2 commits into
mainfrom
perf-parallel-wasm-compile

Conversation

@dsherret

Copy link
Copy Markdown
Member

Wasm plugins were already compiled at the same time as each other, but each module compiled its functions serially, so cold-cache startup was bound by the largest plugin (usually typescript).

This enables wasmtime's parallel-compilation feature and runs each compile on a shared rayon pool:

  • The pool is sized by Environment::max_threads(), so DPRINT_MAX_THREADS now caps compile threads too.
  • All plugins compiling at the same time share the one pool, so there's no oversubscription.
  • The pool is created on the first cache miss and dropped when the last compile finishes, so its threads don't stick around for formatting or in the LSP/editor service.

Costs: rayon becomes a dependency and the Windows release binary grows about 158 KB.

Measurements

Cold plugin cache, median of 5 runs of dprint output-resolved-config against local .wasm files on a 32-core Windows machine. "5 plugins" is typescript, json, markdown, toml and dockerfile. Timings are whole-process wall time and land in roughly 100 ms steps, so small differences aren't meaningful.

Pinned to N cores with CPU affinity:

Cores Before: typescript After: typescript Before: 5 plugins After: 5 plugins
1 1866 ms 1860 ms 3901 ms 3859 ms
2 1841 ms 1259 ms 2428 ms 2054 ms
4 1886 ms 625 ms 1922 ms 1176 ms
8 1887 ms 388 ms 1892 ms 706 ms

All 32 cores available, varying DPRINT_MAX_THREADS:

Threads typescript 5 plugins
before (serial) 1854 ms 1855 ms
1 1857 ms 3875 ms
2 1250 ms 2058 ms
4 646 ms 1152 ms
8 445 ms 751 ms
16 345 ms 646 ms
32 347 ms 551 ms

Warm-cache runs are unaffected since the pool is never created.

Notes

  • Behaviour change: DPRINT_MAX_THREADS=1 on a many-core machine now compiles several plugins one after another (about 3.9 s vs 1.9 s for the five above), because the cap previously didn't apply to compilation.
  • The Pulley target variant (powerpc64, loongarch64, android) also gets the feature but wasn't built or tested locally.

Enables wasmtime's parallel-compilation feature and runs each plugin's compile on a shared rayon pool capped at DPRINT_MAX_THREADS. The pool only lives while something is compiling.
@dsherret
dsherret merged commit 61539bf into main Oct 10, 2026
17 checks passed
@dsherret
dsherret deleted the perf-parallel-wasm-compile branch October 10, 2026 18:16
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