blob: e9fed8d3b705fb90cb689fb02ab7ad97551d1df4 [file] [log] [blame] [view]
bratelldbfab9c22017-07-10 10:10:041# Jumbo / Unity builds
2
3To improve compilation times it is possible to use "unity builds",
4called Jumbo builds, in Chromium. The idea is to merge many
5translation units ("source files") and compile them together. Since a
6large portion of Chromium's code is in shared header files that
7dramatically reduces the total amount of work needed.
8
9## Build instructions
10
11If 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
16Jumbo is currently implemented as a combined `gn` template and a
17python script. Eventually it may become a native `gn` feature. By
Daniel Bratell12a3a5e2017-07-19 11:23:5218(indirectly) using the template `internal_jumbo_target`, each target
19will split into one action to "merge" the files and one action to
20compile the merged files and any files left outside the merge.
bratelldbfab9c22017-07-10 10:10:0421
22Template file: `//build/config/jumbo.gni`
23Merge script: `//build/config/merge_for_jumbo.py`
24
Nico Weber2499aee2017-10-17 20:56:4925### Merge
26
27The "merge" is currently done by creating wrapper files that `#include` the
28source files.
bratelldbfab9c22017-07-10 10:10:0429
30## Jumbo Pros and Cons
31
32### Pros
33
34* Everything compiles significantly faster. When fully enabled
Nico Weber2499aee2017-10-17 20:56:4935 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.
bratelldbfab9c22017-07-10 10:10:0438* Certain code bugs can be statically detected by the compiler when it
Nico Weber2499aee2017-10-17 20:56:4939 sees more/all the relevant source code.
bratelldbfab9c22017-07-10 10:10:0440
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 Bratell2405b442018-06-27 08:51:1654By default at most `50`, or `8` when using goma, files are merged at a
Daniel Bratellebfec4482018-03-02 14:59:1255time. The more files that are are merged, the less total CPU time is
56needed, but parallelism is reduced. This number can be changed by
57setting `jumbo_file_merge_limit`.
bratelldbfab9c22017-07-10 10:10:0458
59## Naming
60
61The term jumbo is used to avoid the confusion resulting from talking
62about unity builds since unity is also the name of a graphical
63environment, a 3D engine, a webaudio filter and part of the QUIC
64congestion control code. Jumbo has been used as name for a unity build
65system in another browser engine.
66
67## Want to make your favourite piece of code jumbo?
68
691. Add `import("//build/config/jumbo.gni")` to `BUILD.gn`.
Daniel Bratell12a3a5e2017-07-19 11:23:52702. 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.
733. Recompile and test.
bratelldbfab9c22017-07-10 10:10:0474
75### Example
76Change from:
77
Daniel Bratell12a3a5e2017-07-19 11:23:5278 source_set("foothing") {
bratelldbfab9c22017-07-10 10:10:0479 sources = [
80 "foothing.cc"
81 "fooutil.cc"
82 "fooutil.h"
83 ]
84 }
85to:
86
87 import("//build/config/jumbo.gni") # ADDED LINE
Daniel Bratell12a3a5e2017-07-19 11:23:5288 jumbo_source_set("foothing") { # CHANGED LINE
bratelldbfab9c22017-07-10 10:10:0489 sources = [
90 "foothing.cc"
91 "fooutil.cc"
92 "fooutil.h"
93 ]
94 }
95
96
97If you see some compilation errors about colliding symbols, resolve
98those by renaming symbols or removing duplicate code. If it's
99impractical to change the code, add a `jumbo_excluded_sources`
100variable to your target in `BUILD.gn`:
101
102`jumbo_excluded_sources = [ "problematic_file.cc" ]`
103
104## More information and pictures
105There are more information and pictures in a
106[Google Document](https://docs.google.com/document/d/19jGsZxh7DX8jkAKbL1nYBa5rcByUL2EeidnYsoXfsYQ)
107
108## Mailing List
109Public discussions happen on the generic blink-dev and chromium-dev
110mailing lists.
111
112https://groups.google.com/a/chromium.org/group/chromium-dev/topics
113
114## Bugs / feature requests
115Related bugs use the label `jumbo` in the bug database.
116See [the open bugs](http://code.google.com/p/chromium/issues/list?q=label:jumbo).