Figma's C++ codebase grew 10% over twelve months. Build times grew 50%. Growth
// the short version
Figma's C++ codebase grew 10% over twelve months. Build times grew 50%. Growth
// what to take away
- A C++ include is a textual paste, so one header can inflate every translation unit downstream.
- Compiled bytes exposed build work that source-line counts and ordinary diffs could not show.
- Figma cut cold build time by trimming heavy headers and enforcing regression budgets in CI.
// transcript
Figma added 10 percent more code and got fifty percent slower builds. More code, slower builds, that's just arithmetic, but fifty against 10 means something else is going on. In C++, including a file doesn't point at it. It essentially pastes it. Before the compiler sees your file, every header it includes gets copied in whole, and every header those headers include, and so on all the way down. So what the compiler is actually handed isn't your 10 line file. It's everything behind it, thousands of times bigger. Now turn that around and look at one header. It's included by dozens of files, and each of those by dozens more, so one header sits behind hundreds of files, and every one of them is carrying its whole weight. Add one innocent include at the top, and you've just handed the compiler another megabyte, in every file that touches it, and the diff shows a single line. So they stopped guessing and gave the invisible thing a number. A tool walks every include chain and totals the bytes the compiler really gets for each file. They call it compiled bytes, and it's the number the build time actually follows. Which is why an include nothing uses is worth deleting, and where a file only needs certain components, you declare the component instead of referencing the whole file. Doing that to just the biggest files cut compiled bytes by nearly a third, and cold builds by a quarter. The tool never compiles anything, it just crawls headers and adds up, so it's quick enough to run on every pull request, which is exactly where they put it. Every change gets measured, and anything that inflates compiled bytes is flagged before it merges. And most of what it catches isn't a mistake. It's that innocent include again, one somebody genuinely needed, sitting on a header that hundreds of files are behind. Nothing in that file is unused, so nothing anywhere warns you. It catches fifty to a hundred of those a day. Fifty to a hundred slowdowns that used to just happen. All together, build times halved. And none of this was really about C++. Every ecosystem has the same shape: the thing you asked for, and the mountain it quietly drags in behind it. They never made the compiler faster. They just stopped handing it things it never needed.
// source
This explainer is based on Speeding Up C++ Build Times by Figma ↗. The original reporting and technical work belong to its publisher.