Faster Than Ninja
This article dives deep into the performance of build systems, pitting build2 against the highly optimized Ninja. The author meticulously benchmarks and tweaks build2 to demonstrate how a modern, native build system can not only match but exceed Ninja's speed, even while performing more extensive tasks. It offers a fascinating look at the subtle inefficiencies in build processes and clever design choices that yield significant performance gains.
The Lowdown
This story meticulously compares the performance of the build2 build system against Ninja, often considered the 'speed of light' for build systems. The author investigates whether build2, a native build system, can approach or surpass Ninja's build times, using the Xerces-C++ library as a testing ground. The analysis highlights Ninja's minimalist approach versus build2's more comprehensive feature set and the hidden costs of meta-build systems like CMake.
- Initially,
build2is about 11% slower than Ninja for a full build of Xerces-C++ (3.8s vs 3.4s). - However, the article points out that CMake, which generates Ninja files, adds a significant overhead (15.6s), making Ninja's effective build time much longer in a real-world scenario.
- By disabling
build2's more precise change tracking (reverting to Ninja's modification time check),build2's time drops to 3.4s, matching Ninja. - Further optimization by disabling file cache compression makes
build2even faster, completing the build in 3.35s, 2.2% quicker than Ninja. - The author notes that
build2still performs significantly more work than Ninja, such as generating headers and extracting extensive compiler information, tasks often offloaded to CMake for Ninja. - Key design decisions contributing to
build2's speed include aggressive caching to avoid redundant work, multi-threaded execution for housekeeping tasks (unlike Ninja's serial approach), and a sophisticated C/C++ build model that combines header dependency extraction with partial preprocessing into a temporary file cache. - The partial preprocessing approach, by front-loading work and leveraging better temporal locality for file access, surprisingly outperforms Ninja's 'byproduct of compilation' model, especially on Linux with GCC.
Ultimately, build2 proves it can rival or exceed Ninja's speed by fundamentally re-evaluating build system architecture and execution, focusing on parallelization and intelligent caching, rather than merely optimizing existing paradigms.