buildprof: A Process-Tree Profiler That Explained Bun's 5x Build Speedup
A developer skeptical of Bun’s claim that its new Rust build compiled more than 5x faster on Linux than the old Zig version built buildprof, an open-source Linux tracing tool, to find the real cause. Instead of integrating with each build system, buildprof records the entire process tree spawned by any build command (prefix your existing command with buildprof --) and lays every process and subprocess on a single timeline, tracking duration, parallelism, and the files passed between steps. Because compilers, linkers, code generators, and custom scripts all show up as processes, the approach works across Cargo, Ninja, Make, Zig, and ad-hoc scripts alike.
Reproducing both Bun builds on a 6-core VM, the author traced where the 24-minute Zig build actually spent its time: a single ld.lld linker invocation ran alone for over 16 minutes—roughly two-thirds of the build. Enabling LLD’s internal timing traces confirmed the culprit was Full LTO, which pulls all compilation units into one serial optimization job that generates machine code at link time. The Rust build, by contrast, used ThinLTO and linked in about 2m24s. The language difference was largely a red herring; the LTO configuration explained most of the gap.
Switching Bun’s own Zig code to ThinLTO shaved only about 3m40s, because much of the remaining time went to compiling JavaScriptCore. Bun doesn’t build WebKit itself—it downloads prebuilt libraries, and the Zig-era build pulled a WebKit revision compiled with Full LTO, forcing the linker to re-optimize that code regardless of Bun’s own flags. The takeaway: headline build-speed comparisons often conflate many variables, and process-level tracing can pinpoint which one actually matters.
Read the full article
Continue reading at Hacker News →This is an AI-generated summary. Read the original for the full story.