A developer has created buildprof, an open-source tool designed to trace and visualize where time is spent during software compilation on Linux systems. By recording every process spawned during a build and displaying them on a timeline, buildprof helps developers pinpoint inefficiencies such as poor parallelism, repeated work, or lengthy compiler and linker invocations.

The motivation for buildprof came from a puzzling claim about the Bun JavaScript runtime: its new Rust-based build was reportedly more than five times faster on Linux than the previous Zig-based build. This was surprising because Zig projects typically compile faster than Rust ones of similar complexity. The developer sought to understand the cause of this discrepancy.

Using buildprof, the developer replayed Bun’s continuous integration builds on a controlled Linux environment. The profiling revealed that the Zig build’s long compile time was dominated by a single linker invocation running Full Link-Time Optimization (LTO), which took over sixteen minutes. In contrast, the Rust build used ThinLTO, resulting in a significantly faster linking phase of just over two minutes.

Further investigation showed that simply switching Bun’s Zig build to ThinLTO reduced linking time but did not fully close the gap. A major factor was that Bun’s build included precompiled WebKit libraries built with Full LTO, which still required extensive optimization during linking. Rebuilding these dependencies with ThinLTO reduced the overall build time from twenty-four to fifteen minutes.

Another key insight was structural: the Rust build was divided into over 90 crates, enabling better parallelism, while the Zig build compiled as a single large module. This limited parallel compilation and contributed to longer build and linking times.

Buildprof operates by tracing process trees using Linux’s ptrace interface, capturing subprocesses and their durations without requiring integration with specific build systems. It also tracks file reads and writes to map dependencies between build steps. The tool’s user interface is based on an extensible fork of the Perfetto UI, allowing detailed exploration of build timelines and compiler internals.

The developer noted that existing tools either lacked comprehensive coverage across build systems or did not provide detailed timelines of subprocesses. Buildprof fills this gap by offering a build-system-agnostic, detailed visualization of the entire build process.

Looking ahead, the developer plans to improve buildprof’s performance, add support for macOS and potentially Windows, and extend compatibility with other build systems like npm, Gradle, and Bazel. Features such as automatic critical path detection are also under consideration.

Buildprof is now available on GitHub and offers a valuable resource for developers seeking to optimize slow builds by revealing hidden bottlenecks and inefficiencies in their compilation workflows.