加快C++构建时间

If you’ve worked with C++ projects, you’re probably all too familiar with the perennial issue of slow build times. They are a major productivity killer, leaving developers stuck in a frustrating cycle of wait, debug, and rebuild. In 2023, build times at Figma were increasing at a disproportionate rate: While the codebase grew by just 10% in a 12-month period, build times had increased by a whopping 50%. It’s no surprise that in our annual internal developer survey, C++ build times were a top pain point. After trying a few stopgap solutions—like purchasing M1 Maxs for our team—build times gradually reverted to their original pace; Ccache and remote caching weren’t enough either. We needed to take more drastic measures, quickly.

如果您曾经使用过C++项目,您可能对构建时间过长的问题非常熟悉。它们是一种严重影响生产力的问题,使开发人员陷入令人沮丧的等待、调试和重新构建的循环中。在2023年,Figma的构建时间以不成比例的速度增长:尽管代码库在12个月内仅增长了10%,但构建时间却增加了整整50%。毫不奇怪,在我们的年度内部开发者调查中,C++构建时间是一个最大的痛点。尝试了一些权宜之计,比如为我们的团队购买M1 Maxs,构建时间逐渐恢复到原来的速度;Ccache和远程缓存也不够。我们需要采取更激进的措施,快速解决问题。

A Figma file showing jokes that the team collected about slow build times.

We even spun up a channel for engineers to joke about slow build times while, of course, brainstorming fixes.

我们甚至开设了一个频道,让工程师们开玩笑说慢构建时间的问题,当然也在脑力激荡中寻找解决方案。

How C++ builds work

C++构建工作原理

Header files contain function declarations, definitions of classes, or constant values that can be used across multiple source files. Header files are included at the beginning of a source file using the #include directive, allowing the compiler to reference the contents during the compilation process.

头文件包含函数声明、类的定义或可在多个源文件中使用的常量值。头文件在源文件的开头使用#include指令进行包含,允许编译器在编译过程中引用其内容。

Before we dive into how we improved C++ build times at Figma, it’s important to understand how C++ compilation works. In the pre-processing step of C++ compilation, all the files that are included (known as header files) get mashed into a single mega-file that is passed to the compiler. This includes files that are transitively included—for example, if file C includes file B, and file B includes file A, then file C includes all the bytes of file A through its transitive dependency.

在我们深入了解...

开通本站会员,查看完整译文。

trang chủ - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.3. UTC+08:00, 2024-11-28 19:28
浙ICP备14020137号-1 $bản đồ khách truy cập$