bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 1 | # Jumbo / Unity builds |
| 2 | |
| 3 | To improve compilation times it is possible to use "unity builds", |
| 4 | called Jumbo builds, in Chromium. The idea is to merge many |
| 5 | translation units ("source files") and compile them together. Since a |
| 6 | large portion of Chromium's code is in shared header files that |
| 7 | dramatically reduces the total amount of work needed. |
| 8 | |
| 9 | ## Build instructions |
| 10 | |
| 11 | If jumbo isn't already enabled, you enable it in `gn` by setting |
| 12 | `use_jumbo_build = true` then compile as normal. |
| 13 | |
| 14 | ## Implementation |
| 15 | |
| 16 | Jumbo is currently implemented as a combined `gn` template and a |
| 17 | python script. Eventually it may become a native `gn` feature. By |
Daniel Bratell | 12a3a5e | 2017-07-19 11:23:52 | [diff] [blame] | 18 | (indirectly) using the template `internal_jumbo_target`, each target |
| 19 | will split into one action to "merge" the files and one action to |
| 20 | compile the merged files and any files left outside the merge. |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 21 | |
| 22 | Template file: `//build/config/jumbo.gni` |
| 23 | Merge script: `//build/config/merge_for_jumbo.py` |
| 24 | |
Nico Weber | 2499aee | 2017-10-17 20:56:49 | [diff] [blame] | 25 | ### Merge |
| 26 | |
| 27 | The "merge" is currently done by creating wrapper files that `#include` the |
| 28 | source files. |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 29 | |
| 30 | ## Jumbo Pros and Cons |
| 31 | |
| 32 | ### Pros |
| 33 | |
| 34 | * Everything compiles significantly faster. When fully enabled |
Nico Weber | 2499aee | 2017-10-17 20:56:49 | [diff] [blame] | 35 | everywhere this can save hours for a full build (binaries and tests) |
| 36 | on a moderate computer. Linking is faster because there is less |
| 37 | redundant data (debug information, inline functions) to merge. |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 38 | * Certain code bugs can be statically detected by the compiler when it |
Nico Weber | 2499aee | 2017-10-17 20:56:49 | [diff] [blame] | 39 | sees more/all the relevant source code. |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 40 | |
| 41 | ### Cons |
| 42 | |
| 43 | * By merging many files, symbols that have internal linkage in |
| 44 | different `cc` files can collide and cause compilation errors. |
| 45 | * The smallest possible compilation unit grows which can add |
| 46 | 10-20 seconds to some single file recompilations (though link |
| 47 | times often shrink). |
| 48 | |
| 49 | ### Mixed blessing |
| 50 | * Slightly different compiler warnings will be active. |
| 51 | |
| 52 | ## Tuning |
| 53 | |
Daniel Bratell | 2405b44 | 2018-06-27 08:51:16 | [diff] [blame] | 54 | By default at most `50`, or `8` when using goma, files are merged at a |
Daniel Bratell | ebfec448 | 2018-03-02 14:59:12 | [diff] [blame] | 55 | time. The more files that are are merged, the less total CPU time is |
| 56 | needed, but parallelism is reduced. This number can be changed by |
| 57 | setting `jumbo_file_merge_limit`. |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 58 | |
| 59 | ## Naming |
| 60 | |
| 61 | The term jumbo is used to avoid the confusion resulting from talking |
| 62 | about unity builds since unity is also the name of a graphical |
| 63 | environment, a 3D engine, a webaudio filter and part of the QUIC |
| 64 | congestion control code. Jumbo has been used as name for a unity build |
| 65 | system in another browser engine. |
| 66 | |
| 67 | ## Want to make your favourite piece of code jumbo? |
| 68 | |
| 69 | 1. Add `import("//build/config/jumbo.gni")` to `BUILD.gn`. |
Daniel Bratell | 12a3a5e | 2017-07-19 11:23:52 | [diff] [blame] | 70 | 2. Change your target, for instance `static_library`, to |
| 71 | `jumbo_static_library`. So far `source_set`, `component`, |
| 72 | `static_library` and `split_static_library` are supported. |
| 73 | 3. Recompile and test. |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 74 | |
| 75 | ### Example |
| 76 | Change from: |
| 77 | |
Daniel Bratell | 12a3a5e | 2017-07-19 11:23:52 | [diff] [blame] | 78 | source_set("foothing") { |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 79 | sources = [ |
| 80 | "foothing.cc" |
| 81 | "fooutil.cc" |
| 82 | "fooutil.h" |
| 83 | ] |
| 84 | } |
| 85 | to: |
| 86 | |
| 87 | import("//build/config/jumbo.gni") # ADDED LINE |
Daniel Bratell | 12a3a5e | 2017-07-19 11:23:52 | [diff] [blame] | 88 | jumbo_source_set("foothing") { # CHANGED LINE |
bratell | dbfab9c2 | 2017-07-10 10:10:04 | [diff] [blame] | 89 | sources = [ |
| 90 | "foothing.cc" |
| 91 | "fooutil.cc" |
| 92 | "fooutil.h" |
| 93 | ] |
| 94 | } |
| 95 | |
| 96 | |
| 97 | If you see some compilation errors about colliding symbols, resolve |
| 98 | those by renaming symbols or removing duplicate code. If it's |
| 99 | impractical to change the code, add a `jumbo_excluded_sources` |
| 100 | variable to your target in `BUILD.gn`: |
| 101 | |
| 102 | `jumbo_excluded_sources = [ "problematic_file.cc" ]` |
| 103 | |
| 104 | ## More information and pictures |
| 105 | There are more information and pictures in a |
| 106 | [Google Document](https://docs.google.com/document/d/19jGsZxh7DX8jkAKbL1nYBa5rcByUL2EeidnYsoXfsYQ) |
| 107 | |
| 108 | ## Mailing List |
| 109 | Public discussions happen on the generic blink-dev and chromium-dev |
| 110 | mailing lists. |
| 111 | |
| 112 | https://groups.google.com/a/chromium.org/group/chromium-dev/topics |
| 113 | |
| 114 | ## Bugs / feature requests |
| 115 | Related bugs use the label `jumbo` in the bug database. |
| 116 | See [the open bugs](http://code.google.com/p/chromium/issues/list?q=label:jumbo). |