Firefox developers have successfully implemented a new caching mechanism for WebIDL code generation, reducing build times by 17% on Linux environments. The update leverages Buildcache’s unique Lua plugin system to intercept Python-based build actions that were previously ignored by traditional compiler caches like ccache and sccache.
By utilizing a new Lua wrapper, the build process can now recognize and cache the output of the `mozbuild.action.webidl` command. This step generates thousands of C++ files from hundreds of WebIDL source files. While the step is deterministic, it previously ran from scratch during every clobber build.
Optimizing the build cycle
According to technical documentation from the project, the fix involves a small change to the `dom/bindings/Makefile.in` file. The update allows the `py_action` macro to pass a command wrapper to Python build actions when Buildcache is active. This enables Buildcache to intercept the WebIDL process and apply its hashing logic to the inputs and outputs.
Developer testing shows significant performance gains during warm builds. In a standard Linux environment, a clean build took 5 minutes and 35 seconds. Using Buildcache with the new WebIDL plugin reduced that time to just 1 minute and 12 seconds.
Comparing tools, Buildcache outperformed ccache and sccache in warm build scenarios. While ccache reduced a build to 3 minutes and 21 seconds, the Buildcache plugin implementation shaved an additional 15 seconds off the process.
The developer behind the implementation noted that while the WebIDL improvement is not revolutionary on its own, it proves the viability of the mechanism. The plugin uses Buildcache’s `direct_mode` capability to hash input files directly, bypassing the need for a C preprocessor.
This implementation serves as a proof of concept for other deterministic build steps. Developers plan to explore applying the same Lua-based approach to other Python-driven codegen actions within the Firefox build pipeline to further accelerate the edit-compile-test cycle.