Erik Staab | fd0792a | 2024-07-12 13:02:21 | [diff] [blame] | 1 | # Clang and C++ Modules in Chromium |
| 2 | |
| 3 | ## Overview |
| 4 | |
| 5 | Modules in C++ have the potential to significantly speed up building Chromium. |
| 6 | With textual inclusion, many headers are re-parsed over |
| 7 | [35000 times](https://commondatastorage.googleapis.com/chromium-browser-clang/include-analysis.html) |
| 8 | and with modules could be reduced to the order of 10 times. |
| 9 | |
| 10 | Clang supports two types of modules: |
| 11 | [Clang header modules](https://clang.llvm.org/docs/Modules.html) and |
| 12 | [C++20 modules](https://clang.llvm.org/docs/StandardCPlusPlusModules.html) (also |
| 13 | called Clang Modules and Standard C++ Modules). We're currently exploring Clang |
| 14 | header modules because: |
| 15 | 1. Other projects (e.g. internally at Google) have had success deploying them to |
| 16 | their code bases with large performance wins. |
| 17 | 2. They can be experimented with without rewrites to the code base or changes to |
| 18 | the build system. |
| 19 | |
| 20 | We're currently experimenting with modules for libc++ and they can be enabled |
Takuto Ikuta | 637a4d9 | 2025-07-16 01:53:42 | [diff] [blame] | 21 | with the GN arg `use_clang_modules. Using this arg is not currently |
Matt Stark | a1ff53c | 2025-05-30 04:07:05 | [diff] [blame] | 22 | recommended, due to the limitations mentioned below. |
Takuto Ikuta | 7d1b2b0b | 2025-02-05 06:53:22 | [diff] [blame] | 23 | It is only interesting to people working on the feature. |
Erik Staab | fd0792a | 2024-07-12 13:02:21 | [diff] [blame] | 24 | |
| 25 | ## Current limitations |
| 26 | |
Erik Staab | fd0792a | 2024-07-12 13:02:21 | [diff] [blame] | 27 | ### Performance |
| 28 | |
| 29 | With Chrome's Clang plugins turned on, modules perform worse than without |
Matt Stark | a1ff53c | 2025-05-30 04:07:05 | [diff] [blame] | 30 | modules ([crbug.com/351909443](https://crbug.com/351909443)). |
Erik Staab | fd0792a | 2024-07-12 13:02:21 | [diff] [blame] | 31 | |
Matt Stark | a1ff53c | 2025-05-30 04:07:05 | [diff] [blame] | 32 | ### Configurations |
| 33 | |
| 34 | Clang modules don't play nice with code with RTTI / exceptions depending on |
| 35 | code without, and vice versa. Work is ongoing to fix this, but for now, it |
| 36 | remains a problem ([crbug.com/403415459](https://crbug.com/403415459)). |
Erik Staab | fd0792a | 2024-07-12 13:02:21 | [diff] [blame] | 37 | |
| 38 | ### Correctness |
| 39 | |
Matt Stark | a1ff53c | 2025-05-30 04:07:05 | [diff] [blame] | 40 | The configurations issue above can cause unexpected build failures. |