[TOC]
The compile-size
trybot measures and prevents unexpected growth in the size of
the C++ compiler input size, which closely correlates with time
spent in the build.
This builder does the following:
- With the CL and without the CL applied:
- Builds
chrome
on Linux - Queries siso for build deps and commands
- Generates a compile size report broken down by TU (translation unit)
- Builds
- Compares the two reports and writes a diff report with a summary and TU deltas
- If a size increase threshold is exceeded and there is no override then fail the build
- Inspect the report
- Iterate on a fix
- Run locally to collect a baseline (or skip this to iterate remotely)
- If applicable, remove transitive includes by using forward declarations
- If stuck, ask for help
- If still stuck, override the builder
- Confirm results reproduce remotely
- On the
compile-size
builder's overview or infra page look for the summary and the link to thecompile_size_deltas.txt
report. - The report shows translation units with the largest increases. These can
give clues about the source of the increase. For example, when many TUs
show a similar increase in size, it could mean that a header was added to
be transitively included in all of those TUs.
If you want to check TU sizes locally to iterate faster, do the following:
# Set up a new build directory with the builder's GN args
tools/mb/mb gen -m tryserver.chromium.linux -b compile-size out/compile_size
# Build the `chrome` target
autoninja -C out/compile_size chrome
# Collect the size info
siso query commands -C out/compile_size chrome > /tmp/commands.txt
siso query deps -C out/compile_size > /tmp/deps.txt
tools/clang/scripts/compiler_inputs_size.py out/compile_size \
/tmp/commands.txt /tmp/deps.txt > /tmp/report.txt
The report will contain lines with compile sizes in bytes per TU, like
apps/app_lifetime_monitor.cc 9,034,754
apps/app_lifetime_monitor_factory.cc 5,863,660
apps/app_restore_service.cc 9,198,130
As you make changes, you can re-build, collect size info, and generate reports to see how the per-TU numbers change. Two reports can be diffed with compiler_inputs_size_diff.py.
tools/clang/scripts/compiler_inputs_size_diff.py /tmp/report-old.txt \
/tmp/report-new.txt > /tmp/diff-report.txt
Once done iterating on a fix locally (or if you skipped local iterations), you
can upload a new patchset or CL and trigger the compile-size
builder to get
a new result and report.
A common source of compiler input size growth is adding a header to another widely included header. This can result in the added header getting compiled an additional thousands or tens of thousands of times.
Chromium style prefers forward declarations over includes when a full definition isn't required. For advice on when to use forward declarations and how to minimize code in headers see these tips.
Example CLs replacing header inclusion with forward declarations resulting in large compiler input size decreases:
For help, post to [email protected]. They're expert build system developers. You may also ask #cxx or #halp on Chromium slack.
Not all checks are perfect and sometimes you want to bypass the builder (for example, if you did your best and are unable to reduce compiler input size any further).
Adding a Compile-Size: $ANY_TEXT_HERE
footer to your CL description (above or
below Bug:
) will bypass the builder assertions.
Examples:
Compile-Size: Size increase is unavoidable.
Compile-Size: Increase is temporary.
Compile-Size: See commit description.
<-- use this if longer than one line.
***note
Note: Make sure there are no blank lines between Compile-Size:
and
other footers.
The analysis is done with the following scripts:
- compiler_inputs_size.py: Computes growth between builds, breaking them down by TU.
- compiler_inputs_size_diff.py: Computes deltas from output of the compiler_inputs_size.py script.
The GN args are in the builder's gn-args.json file.