Dune: Concurrent builds are here!

Dune currently wraps all builds with a global mutex:

let build_system_mutex = Fiber.Mutex.create ()

let build f =
  Fiber.Mutex.with_lock build_system_mutex ~f:(fun () ->
    Build_system.run f)

This forces all builds—watch mode, RPC-driven builds, CI tasks, and editor requests—to run one at a time, even when they touch unrelated targets.

The result is unnecessary blocking across common

Here’s my PR that adds concurrent builds to Dune. The PR description explains the design. Implementation comes with proper tests.

I forgot to do this at first but here’s the proposal in a Github issue, with quantified benefits. Think of the PR above as a reference implementation.

3 Likes

To summarize

  • Code complexity: +600 LOC (Build_session, Build_coordinator, dual state
    tracking)
  • Runtime overhead: Negligible (microseconds for mutex operations)
  • Memory overhead: Minimal (~100 bytes per active build session)
  • Sequential builds: Zero overhead (same performance as before)

The concurrent builds implementation delivers 8-9× performance improvements for interactive workflows where fast builds (editor diagnostics) occur during slow builds (full compilation).

2 Likes