SlideShare ist ein Scribd-Unternehmen logo
1 von 73
Downloaden Sie, um offline zu lesen
The Hitchhiker's Guide toThe Hitchhiker's Guide to
FASTER BUILDSFASTER BUILDS
by Viktor Kirilov
1
Me, myself and IMe, myself and I
my name is Viktor Kirilov - from Bulgaria
7+ years of professional C++ in the games / VFX industries
worked only on open source for 3 years (2016-2019)
creator of - the fastest C++ testing frameworkdoctest
 
 
 
 
            !!! not wasting time !!!
Passionate about
2
C++ is known for...C++ is known for...
▲ performance
▲ expressiveness
▲ being multi-paradigm
▼ complexity
▼ metaprogramming could be       
 much more powerful and simple
▼ no standard build system           
 and package management
▼ L0oo0oOoNG COMPILE TIMES
3
Major C++ issue - compile timesMajor C++ issue - compile times
4
This presentationThis presentation
Introduction: WHAT and WHY
precompiled headers
unity builds
hardware
build systems
caching
distributed builds
diagnostics
static vs dynamic linkinglinkers
PIMPL
forward declarations
includes
templates
binary bloat
annotations
modules
parallel builds
toolchains
tooling
5
symbol visibility
compilers
Slides: https://slides.com/onqtam/faster_builds
memes
HOW
RealityReality
some projects take (tens of) hours to compile - WebKit: a big offender 
both minimal and full rebuilds suffer more and more in time
all projects start small - build times increase inevitably
Opera 32 bit on Windows
in 3 years 6 months:
15 minutes to 64+
+ incorporated PCH !!!
6
A unique problem to C++A unique problem to C++
Actually the folks at sympathize with us :DRust
7
Why reduce build timesWhy reduce build times
idle time is costly - lets do the math:
assuming a 80k $ annual salary
1 hour daily for waiting (out of 8 hours: 12.5%)
10k $ per developer annually
value to company > at least x3 the salary
100 developers ==> 3 million $ annually
the unquantifiable effects of long build times
discourage refactoring and experimentation
lead to mental context switches (expensive)
any time spent reducing build times is worthwhile !!! 8
The steps in building C++ codeThe steps in building C++ code
preprocessor: source file => translation unit
includes
macros, conditional compilation (ifdef)
compiler: translation unit => object file
parsing, tokens, AST
optimizations
code generation
linker: object files & libraries => executable
Absolutely fantastic explanation:
https://github.com/green7ea/cpp-compilation 9
Why C++ compilation takes so longWhy C++ compilation takes so long
backwards compatibility with C: a killer feature ==> adoption!!!
inherits the archaic textual include approach
originally for sharing just declarations & structs between TUs
language is complex (ADL, overloads, templates, etc.)
multiple phases of translation - each depending on the previous
not context independent
new standards complicate things further
complex zero-cost abstractions end up in headers
even the preprocessor can become a bottleneck
sub-optimal tools and build system setups
bad project structure - component and header dependencies
touch a header - rebuild everything
10
C vs C++ and different standardsC vs C++ and different standards
compiled as time increase
C 5 sec baseline
C++98 5.6 sec +12%
C++11 5.6 sec +12%
C++17 5.8 sec +14%
compiled as time increase
C++98 8.4 sec baseline
C++11 9.8 sec +17%
C++17 10.8 sec +29%
C codebase (impl)
https://github.com/vurtun/nuklear
C++ codebase (impl + tests) (ver 1.2.8)
https://github.com/onqtam/doctest
Environment: GCC 7.2 on Windows, only compilation: "-c", in Debug: "-O0"
optimizer doesn't care about language/standard: -O2 ==> same diff in seconds
newer standards might be even heavier depending on the code
more constexpr, metaclasses, concepts - further pressure on compilers
constexpr - more complex compiler, but faster compile time algorithms
11
That meme again...That meme again...
12
Why includes suckWhy includes suck
textual - not symbolic
parsed results cannot be cached - macros...
implementation dependencies are leaked/dragged
privately used types by value need the definition
the same code gets compiled many times
the same headers end up used in many sources
M headers with N source files ==> M x N build cost
templates
re-instantiated for the same types
require more code to be in headers
inline functions in headers (this includes templates)
more work for the compiler/linker 13
Standard includes - after the preprocessorStandard includes - after the preprocessor
Header GCC 7 - size lines of code MSVC 2017 - size lines of code
cstdlib 43 kb 1k 158 kb 11k
cstdio 60 kb 1k 251 kb 12k
iosfwd 80 kb 1.7k 482 kb 23k
chrono 190 kb 6.6k 841 kb 31k
variant 282 kb 10k 1.1 mb 43k
vector 320 kb 13k 950 kb 45k
algorithm 446 kb 16k 880 kb 41k
string 500 kb 17k 1.1 mb 52k
optional 660 kb 22k 967 kb 37k
tuple 700 kb 23k 857 kb 33k
map 700 kb 24k 980 kb 46k
iostream 750 kb 26k 1.1 mb 52k
memory 852 kb 29k 1.0 mb 40k
random 1.1 mb 37k 1.4 mb 67k
functional 1.2 mb 42k 1.4 mb 58k
regex 1.7 mb 64k 1.5 mb 71k
ALL OF THEM 2.6mb 95k 2.3mb 98k 14
Boost includes - after the preprocessorBoost includes - after the preprocessor
Header GCC 7 - size lines of code MSVC 2017 - size lines of code
hana 857 kb 24k 1.5 mb 69k
optional 1.6 mb 50k 2.2 mb 90k
variant 2 mb 65k 2.5 mb 124k
function 2 mb 68k 2.6 mb 118k
format 2.3 mb 75k 3.2 mb 158k
signals2 3.7 mb 120k 4.7 mb 250k
thread 5.8 mb 188k 4.8 mb 304k
asio 5.9 mb 194k 7.6 mb 513k
wave 6.5 mb 213k 6.7 mb 454k
spirit 6.6 mb 207k 7.8 mb 563k
geometry 9.6 mb 295k 9.8 mb 448k
ALL OF THEM 18 mb 560k 16 mb 975k
environment: C++17, GCC 7, VS 2017, Boost version: 1.66
100 .cpp files including geometry ==> 1 GB of source code!
not meant to discredit Boost - this is a C++ issue
15
Insert title of slideInsert title of slide
16
GCC/Clang warning: -Wunused, -Wunused-function
-ffunction/data-sections -Wl,--gc-sections,--print-gc-sections
 --enable=unusedFunction
 - DEADCODE/UNREACHABLE
 by scitools
 - static and dynamic
... also runtime coverage ( (& lcov for GUI), others)
cppcheck
Coverity
Understand
CppDepend
PVS Studio
OCLint
Parasoft C/C++ Test
Polyspace
oovcde dead code detection
others gcov
Unreachable (dead) codeUnreachable (dead) code
The C++ philosophy: "don't pay for what you don't use"
might also uncover bugs
& improve runtime!
17
compile in Debug instead of Release if feasible
-O0, -O1, -O2, -O3, -Os - different results!
unused sources/libraries
look for such after dead code removal
often a problem with makefiles and old cruft
MSVC warning LNK4221: This object file does not
define any previously undefined public symbols
compile each source file just once
scan the build logs for such instances
commonly used sources => static libraries
Other low hanging fruitOther low hanging fruit
18
strive for loose coupling
specific includes is better than #include "everything.h"
more granular rebuilds when touching headers
 - the most popular (Clang-based)
 
(or the ) -
 << also has a test runner for doctest!
 - plugin for Eclipse CDT (or the )
ProFactor IncludeManager -
MSVC: /showIncludes      GCC: -H
https://include-what-you-use.org/
Doxygen + Graphviz
https://github.com/myint/cppclean
Header Hero fork article
https://github.com/tomtom-international/cpp-dependencies
ReSharper C++ Includes Analyzer
Includator Cevelop IDE
https://gitlab.com/esr/deheader
https://www.profactor.co.uk/
Finding unnecessary includesFinding unnecessary includes
find_program(iwyu_path NAMES include-what-you-use iwyu)
set_property(TARGET hello PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path})
19
Declarations vs definitions - functionsDeclarations vs definitions - functions
// interface.h
int foo(); // fwd decl - definition is in a source file somewhere
inline int bar() { // needs to be inline if the body is in a header
return 42;
}
struct my_type {
int method { return 666; } // implicitly inline - can get inlined!
};
template <typename T> // a template - "usually" has to be in a header
T identity(T in) { return in; } // implicitly inline
move function definitions out of headers
builds will be faster
use link time optimizations for inlining (or unity builds!)
some optimizations for templates exist - in later slides 20
Declarations vs definitions - typesDeclarations vs definitions - types
// interface.h
#pragma once
struct foo; // fwd decl - don't #include "foo.h"!
#include "bar.h" // drag the definition of bar
struct my_type {
foo f_1(foo obj); // fwd decl used by value in signature - OK
foo* foo_ptr; // fwd decl used as pointer - OK
bar member; // requires the definition of bar
};
// interface.cpp
#include "interface.h"
#include "foo.h" // drag the definition of foo
foo my_type::f_1(foo obj) { return obj; } // needs the definition of f
21
used by value
including in class definitions (size for memory layout)
not in function declarations !!!
 
types are used by reference/pointer
pointer size is known by the compiler (4/8 bytes)
compiler doesn't need to know the size of types
types are used by value in function declarations
either as a return type or as an argument
this is less known !!!
function definition will still need the full type definition
call site also needs the full type definition
Declarations vs definitions - typesDeclarations vs definitions - types
definition of types is necessary only when they are:
forward declarations are enough if:
22
PIMPL - pointer to implementationPIMPL - pointer to implementation
AKA compilation firewall
holds a pointer to the implementation type
// widget.h
struct widget {
widget();
~widget(); // cannot be defaulted here
void foo();
private:
struct impl; // just a fwd decl
std::unique_ptr<impl> m_impl;
};
// widget.cpp
struct widget::impl {
void foo() {}
};
widget::widget() : m_impl(std::make_unique<widget::impl>()) {}
widget::~widget() = default; // here it is possible
void widget::foo() { m_impl->foo(); }
23
PIMPL - pros & consPIMPL - pros & cons
breaks the interface/implementation dependency
less dragged headers ==> better compile times!
implementation data members no longer affect the size
helps with preserving ABI when changing the implementation
lots of APIs use it (example: Autodesk Maya)
 
requires allocation, also space overhead for pointer
can use allocators
extra indirection of calls - link time optimizations can help
more code
PROS:
CONS:
on const propagation, moves, copies and other details:
http://en.cppreference.com/w/cpp/language/pimpl 24
Abstract interfaces & factoriesAbstract interfaces & factories
// interface.cpp
#include "interface.h"
// implementation 1
struct Derived_1 : public IBase {
int data;
Derived_1(int in) : data(in) {}
int do_stuff() override { return data; }
};
// implementation 2
struct Derived_2 : public IBase {
int do_stuff() override { return 42; }
};
// factory functions
std::unique_ptr<IBase> make_der_1(int in) {
return std::make_unique<Derived_1>(in);
}
std::unique_ptr<IBase> make_der_2() {
return std::make_unique<Derived_2>();
}
// interface.h
struct IBase {
virtual int do_stuff() = 0;
virtual ~IBase() = default;
};
// factory functions
std::unique_ptr<IBase> make_der_1(int);
std::unique_ptr<IBase> make_der_2();
Implementations of derived
classes are obtained
through factory functions
25
Abstract interfaces & factoriesAbstract interfaces & factories
breaks the interface/implementation dependency
helps with preserving ABI (careful with the virtual interface)
 
 
requires allocation, also space overhead for pointer
extra indirection of calls (virtual)
more code
users work with (smart) pointers instead of values
link time optimizations - harder than for PIMPL
PROS:
CONS:
26
Precompiled headersPrecompiled headers
put headers that are used in many of the sources
put headers that don't change often
do regular audits to reflect the latest project needs
often disregarded as a hack by many - HUGE mistake IMHO
easy setup and benefits can be huge
// precompiled.h
#pragma once
// system, runtime, STL
#include <cstdio>
#include <vector>
#include <map>
// third-party
#include <dynamix/dynamix.hpp>
#include <doctest.h>
// rarely changing project-specific
#include "utils/singleton.h"
#include "utils/transform.h"
27
Precompiled headers - usagePrecompiled headers - usage
supported by mainstream compilers
MSVC: "/Yc" & "/Yu"
GCC/Clang: "-x c++-header"
only one PCH per translation unit :(
force-include for convenience
/FI (MSVC) or -include (GCC/Clang)
build system support
(native)
(native)
 (native)
CMake - with modules
Meson
Buck
FASTBuild
cotire
cmake-precompiled-header 28
AKA: amalgamated, jumbo, SCU
include all original source files in one (or a few) unity source file(s)
Unity buildsUnity builds
// unity file
#include "core.cpp"
#include "widget.cpp"
#include "gui.cpp"
headers get parsed only once if included from multiple sources
less compiler invocations
less instantiation of the same templates
HIGHLY underrated
NOT because of reduced disk I/O - filesystems cache aggressively
less linker work
used at Ubisoft (14+ years), Unreal, WebKit
The main benefit is compile times:
29
up to 10+ times faster (depends on modularity)
best gains: short sources + lots of includes
faster (and not slower) LTO (WPO/LTCG)
ODR (One Definition Rule) violations get caught
this one is huge - still no reliable tools
.
.
 
enforces code hygiene
include guards in headers
no statics and anon namespaces in headers
less copy/paste of types & inline functions
Unity builds - prosUnity builds - pros
// a.cpp
struct Foo {
// implicit inline
int method() { return 42; }
};
// b.cpp
struct Foo {
// implicit inline
int method() { return 666; }
};
30
might slow down some workflows
minimal rebuilds
might interfere with parallel compilation
these ^^ can be solved with tuning/configuring
some C++ stops compiling as a unity
clashes of symbols in anonymous namespaces
overload ambiguities
using namespaces in sources
preprocessor
miscompilation - rare (but possible)
successful compilation with a wrong result
preprocessor, overloads (also non-explicit 1 arg constructors)
good tests can help!
Unity builds - consUnity builds - cons
31
 (as a CMake module, there are others)
(build system)
experimental support for Unity builds
 
can produce multiple unity source files
can exclude files (if problematic, or for incremental builds)
 
(build system)
(build system)
(Visual Studio extension)
custom solution
cotire
FASTBuild
Visual Studio
Meson
waf
RudeBuild
Unity builds - how to maintainUnity builds - how to maintain
these:
others:
32
__declspec(noinline) / __attribute__((noinline))
and careful with __forceinline / __attribute__((always_inline))
leads to compile time savings
might even help with runtime (instruction cache bloat)
implicit culprit: destructors
especially for heavily repeated constructs
asserts in testing frameworks
example: - "The fastest feature-rich C++11 single-
header testing framework"
doctest
CppCon 2017: Viktor Kirilov "Mix Tests and Production Code
With Doctest - Implementation and usage"
Inlining annotationsInlining annotations
explicitly disable inlining:
33
linkers sometimes can fold identical functions - but more work
only if proven you aren't taking their addresses (required by the standard)
this way: less work for the compiler/linker
now it is syntactically easier to move function bodies out of the header
use link time optimizations for inlining (or unity builds!)
Templates - argument-independent codeTemplates - argument-independent code
template <typename T>
class my_vector {
int m_size;
// ...
public:
int size() const { return m_size; }
// ...
};
// my_vector<T>::size() is instantiated
// for types such as int, char, etc...
// even though it doesn't depend on T
class my_vector_base { // type independent
protected: // code is moved out
int m_size;
public:
int size() const { return m_size; }
};
template <typename T> // type dependent
class my_vector : public my_vector_base {
// ...
public:
// ...
};
34
Templates - C++11 extern templateTemplates - C++11 extern template
// interface.h
#include <vector>
template <typename T>
T identity(T in) { return in; }
// somewhere.cpp
#include "interface.h"
// do not instantiate these templates here
extern template int identity<int>(int);
extern template float identity<float>(float);
extern template class std::vector<int>;
// will not instantiate
auto g_int = identity(5);
auto g_float = identity(15.f);
std::vector<int> a;
// will instantiate for bool
auto g_unsigned = identity(true);
no instantiation/codegen where extern-ed but still has to be parsed...
precompiled headers or unity builds !!!!
some STL implementations do it for std::basic_string<char, ...>
https://arne-mertz.de/2019/02/extern-template-reduce-compile-times/
// somewhere_else.cpp
#include "interface.h"
// instantiation for float
template float identity<float>(float);
// instantiation for std::vector<int>
template class std::vector<int>;
// instantiation for identity<int>()
auto g_int_2 = identity(1);
35
the class/function has to be explicitly instantiated somewhere
for all types it is used with... or linker errors!
Templates - move functions out of headersTemplates - move functions out of headers
// interface.h
// declaration
template <typename T>
T identity(T in);
template <typename T>
struct answer {
// declaration
T calculate();
};
// interface.cpp
#include "interface.h"
// definition
template <typename T>
T identity(T in) { return in; }
// definition
template <typename T>
T answer<T>::calculate() {
return T(42);
}
// explicit instantiations for int/float
template int identity<int>(int);
template float identity<float>(float);
// explicit instantiation for int
template struct answer<int>;
// user.cpp
#include "interface.h"
auto g_int = identity(666);
auto g_float = identity(0.541f);
auto g_answer = answer<int>().calculate();
36
The "Rule of ":
1. looking up a memoized type
2. adding a parameter to an alias call
3. adding a parameter to a type
4. calling an alias
5. instantiating a type
6. instantiating a function template
7. SFINAE
Chiel
Templates - cost of operationsTemplates - cost of operations
A fascinating talk:
code::dive 2017 – Odin Holmes – The fastest
template metaprogramming in the West
37
use variadic templates sparingly
recursive templates are bad business
especially when not memoized
recursive template arguments are even worse
now that we have "constexpr if" we can use a lot less SFINAE
if constexpr might be preferrable even to tag dispatching
Templates - other notesTemplates - other notes
38
 - interactive template metaprogramming shell
Clang-based
GUI:
Clang-based
profile time/memory consumption of template instantiations
interactive debugging sessions
IDE (Eclipse CDT based) - Template Visualization
metashell
https://github.com/RangelReale/msgui
https://github.com/mikael-s-persson/templight
https://github.com/mikael-s-persson/templight-tools
Cevelop
Templates - toolsTemplates - tools
39
reducing compile times of -generated code: type tags to
circumvent SFINAE and use overload resolution
diagnostics
-ftime-report - breakdown of time spent in compiler phases
templight
 - Alternative title: "Boost your TMP-Fu"
metaprogramming through composition
builds onto his previous talk
brigand, kvasir, metal, mp11 -
CppCon 2017: Eddie Elizondo “Optimizing compilation times with
Templates”
Thrift
C++Now 2018: Odin Holmes “Boost.TMP: Your DSL for
Metaprogramming”
http://metaben.ch/
Templates - other good talksTemplates - other good talks
40
-ftime-report - breakdown of different compiler phases
-ftime-trace (Clang) - - by Aras Pranckevičius
 
/Bt - frontend & backend (optimizer/codegen)
/time - for the linker
/d2cgsummary - Anomalistic Compile Times for functions
first advertised by Aras Pranckevičius -
/d1reportTime - includes, classes, functions - times -
/d1templateStats
thanks to these flags
Chrome tracing flamegraph
"Best-unknown-MSVC-flag"
blog post
surprising 1 line fix => 20% faster builds
Updating VS 2017 15.6 to 15.8 => 2x slower for template instantiations
Diagnostics - compilationDiagnostics - compilation
some functions trigger pathological cases (or bugs) in compilers/optimizers
Clang/GCC:
MSVC:
41
Bloaty McBloatface: a size profiler for ELF/Mach-O binaries
Sizer: Win32/64 executable size report utility
SymbolSort: measuring C++ code bloat in Windows binaries
twiggy: call graph analyzer (wasm only, no ELF/Mach-O/PE/COFF yet)
nm - Unix tool to inspect the symbol table of binaries
nm --print-size --size-sort --demangle --radix=d YOUR_BINARY
dumpbin: Microsoft COFF Binary File Dumper
common culprit: templates (because length of names matters!!!)
demangling: undname.exe / c++filt /
https://github.com/google/bloaty
https://github.com/aras-p/sizer
https://github.com/adrianstone55/SymbolSort
https://github.com/rustwasm/twiggy
https://demangler.com
Diagnostics - binary bloatDiagnostics - binary bloat
42
Build systemsBuild systems
Make
MSBuild
FASTBuild
Ninja
Buck
Bazel
Scons
Autotools
JamBoost.Build
Qmake
CMake
tup
build2
shake
IncrediBuild
Meta build systems:
Gyp
Waf
Meson
43
Premake
Custom...XCode
Please
Tundra
GN
Build systemsBuild systems
"g++ src1.cpp src2.cpp ..."  is not a build system
dependency tracking - for minimal and parallel rebuilds
help managing scale
includes, flags, link libs
help with refactoring/restructuring
help with tool integration
not all are created equal
HUGE topic (trade-offs, approaches) - but lets focus just on speed
most old build systems have high overhead (MSBuild, make)
suboptimal dependency and change detection/scanning
44
Parallel buildsParallel builds
Ninja, FASTBuild, IncrediBuild: best in this regard
make: -jN (and through CMake: "cmake --build . -- -jN")
MSBuild (build system behind Visual Studio):
/MP[processMax] - in CMake: "target_compile_options(target /MP)"
inability to parallelize compilation of dependent dlls
 fixes this when integrated with Visual Studio
thread oversubscription (no overarching scheduler):
8 projects in parallel (8 cpp each + /MP) ==> 64 threads!
Ninja instead of MSBuild as the VS backend!
since recently supports
 - Bruce Dawson
careful with unity builds and "long poles"
modern LTO/LTCG technology is parallelizable too
IncrediBuild
running Custom Build Tools in parallel
Make VC++ Compiles Fast Through Parallel Compilation
45
Diagnosing/monitoring parallelismDiagnosing/monitoring parallelism
 - Bruce DawsonMake VC++ Compiles Fast Through Parallel Compilation
46
Diagnosing/monitoring parallelismDiagnosing/monitoring parallelism
 build monitorIncrediBuild 47
Diagnosing/monitoring parallelismDiagnosing/monitoring parallelism
Chrome's  (flame graph) - chrome://tracing/about:tracing
build system
not related to
parallelism, but for
-ftime-trace in clang:
ninjatracing
buck
blog post
llvm mailing list
other blog post
48
Sort-of winners (in terms of speed)Sort-of winners (in terms of speed)
FASTBuild
unity builds
precompiled headers
caching
distributed builds
best parallelization
generates project files
multiplatform
multi-compiler
tiny
might get a CMake backend
others...
haven't looked into these yet
buck << by Facebook
bazel << by Google
build2 << modules! :D
meson << hot contender
...
Ninja - less features but crazy
fast - intented to be generated
by a meta-build system
GN (GYP replacement)
can generate ONLY ninja
IndrediBuild
tup
49
big discussion overall - but here we care about build times
much much faster - handles only the exported interface
Static vs dynamic linkingStatic vs dynamic linking
prefer dynamic (.dll, .so, .dylib) over static (.lib, .a)
50
Unix: all symbols exported by default
opposite to Windows - which got the default right!
UNIX: compile with -fvisibility=hidden
improves link time
annotate the required parts of the API for exporting
circumvents the GOT (Global Offset Table) for calls => profit
load times also improved (extreme templates case: 45 times)
reduces the size of your DSO by 5-20%
for details:
clang-cl on windows: => 30% faster chrome build
alternative: -fvisibility-inlines-hidden
all inlined member functions are hidden
no source code modifications needed
careful with local statics in inline functions
can also explicitly annotate with default visibility
https://gcc.gnu.org/wiki/Visibility
/Zc:dllexportInlines-
Dynamic linking - symbol visibilityDynamic linking - symbol visibility
51
Multiplatform symbol export annotationsMultiplatform symbol export annotations
#if defined _WIN32 || defined __CYGWIN__
#define SYMBOL_EXPORT __declspec(dllexport)
#define SYMBOL_IMPORT __declspec(dllimport)
#define SYMBOL_HIDDEN
#else
#define SYMBOL_EXPORT __attribute__((visibility("default")))
#define SYMBOL_IMPORT
#define SYMBOL_HIDDEN __attribute__((visibility("hidden")))
#endif
#ifdef DLL_EXPORTS // on this depends if we are exporting or importing
#define MY_API SYMBOL_EXPORT
#else
#define MY_API SYMBOL_IMPORT
#endif
MY_API void foo();
class MY_API MyClass {
int c;
SYMBOL_HIDDEN void privateMethod(); // only for use within this DSO
public:
MyClass(int _c) : c(_c) { }
static void foo(int a);
};
52
LinkersLinkers
gold (unix)
comes with binutils starting from version 2.19
-fuse-ld=gold
not threaded by default
configure with "--enable-threads"
use: "--threads", "--thread-count COUNT", "--preread-archive-symbols"
lld even faster than gold - - multithreaded by default
Unix: Split DWARF -  - building clang/llvm codebase
10%+ faster full builds and 40%+ faster incremental builds
CMake -
https://lld.llvm.org/
article
LINK_WHAT_YOU_USE
53
Linkers - LTO and other flagsLinkers - LTO and other flags
clang
ThinLTO:
MSVC - lots of improvements, also regarding LTCG
lots of improvements in the recent years
/debug:fastlink – generate partial PDB (new format)
/INCREMENTAL for debug
VS 2019 -
LTCG
/LTCG:incremental
also parallel - /cgthreads:8 instead of the default 4
CppCon 2017: Teresa Johnson “ThinLTO: Scalable and Incremental Link-
Time Optimization”
GCC 8: link time and interprocedural optimization
Visual Studio 2017 Throughput Improvements and Advice
Speeding up the Incremental Developer Build Scenario
from x1.4 to x1.75 faster link times for Chrome with VS 2019
huge speedups (~x2)
54
Compiler cachesCompiler caches
"compiler wrapper" -
maps a hash of:
preprocessed source (TU)
compilation flags
& compiler version
==> to an object file
First run (cold cache) is a bit slower
than without the wrapper
Consecutive >> FULL << rebuilds
are much faster (warm cache) 55
Compiler cachesCompiler caches
For Unix alike:  (GCC, Clang),  (GCC)
For Windows:  (MSVC),  (MSVC)
 - straight out of the build system!
 (GCC, Clang, MSVC)
ccache with cloud storage over AWS S3/GCS/Redis
 (MSVC)
also distributed & with cloud storage
 - a Clang fork - not a wrapper! -
in memory caching server for requested compilations
biggest gains on heavy templates -
recently  - future not clear
x2~x5 times faster -
ccache cachecc1
clcache cclash
http://fastbuild.org/
https://github.com/mozilla/sccache
https://stashed.io/
zapcc mail thread
article
open-sourced
WebKit can compile more benchmarks 56
Compiler cachesCompiler caches
caches work best for full rebuilds - not minimal
Other links:
Faster C++ builds
Speeding up the Build of C and C++ Projects
ccache and CMake:
 
 
 
Using ccache with CMake
Speed up C++ compilation, part 2: compiler cache
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
project(SomeProject)
57
Distributed buildsDistributed builds
take advantage of unused
processing power of computers
prepend in front of compiler
just like caches: distcc gcc ...
caching + distributed builds = ❤
, and
 
watch out: network bottlenecks
include directories - sort em!
bandwidth
here here here
OMG again that build system!!! ==>
some article:
https://github.com/distcc/distcc
https://github.com/icecc/icecream
https://www.incredibuild.com/
http://fastbuild.org/
Speed up C++ compilation, part 3: distributed compilation
export CCACHE_PREFIX=DISTCC
58
HardwareHardware
59
HardwareHardware
more cores
make sure you have enough RAM && parallel builds setup
RAM disks (file system drive in your RAM instead of ssd/hdd)
better than SSDs
don't expect huge gains though...
mount $TEMP as a RAM disk (%TEMP% for windows)
build output to RAM disk (most important - because of the link step)
also put the compiler there!
touches on network I/O issues and many other topics
CppCon 2014: Matt Hargett "Common-sense acceleration of your MLOC build"
60
What if the fundament is badWhat if the fundament is bad
61
Physical designPhysical design
physical structure/design
often neglected
every project starts small... some end up big and it's too late
reasoning about components and modularity - IMPORTANT!!!
physically (and logically): files, dependencies, includes
benefits: fast builds, easy to reason, easy to refactor
Article:
John Lakos (Bloomberg)
book:
multi-part talk: "Advanced Levelization Techniques"
Controversial article:
Physical Structure and C++ - A First Look
"Large-scale C++ Software Design"
C++Now 2018: “C++ Modules & Large-Scale Development”
Physical Design of The Machinery 62
Dependency analysisDependency analysis
cmake --graphviz=[file]
visualize with
some (most) build systems have such a feature ( )
Most tools from the "Finding unnecessary includes" slide
by scitools
- Graphviz
- Graphviz
maybe even
IDE tools
options
Graphviz
bazel
Understand
CppDepend
cpp-dependencies
Doxygen
SourceTrail
Visual Studio Code Maps 63
Dependency analysisDependency analysis
Boost.Variant - - by Stephen KellyBoost dependencies and bcp
Boost.Spirit
Boost.Geometry 64
MODULES
65
Modules - historyModules - history
2004.11.05: first proposal: - Modules in C++
by Daveed Vandevoorde - working on EDG - the only compiler supporting
exported templates (and aiding in their deprecation)
dropped from C++11 after a few revisions ==>
2011: work on - by Douglas Gregor
2014.05.27: standardization continues with - A Module System for C++
by Gabriel Dos Reis, Mark Hall and Gor Nishanov
after a few revisions - didn't enter C++17 - left as a TS
latest work: will enter C++20
2017.06.16:
2018.01.29: - Working Draft, Extensions to C++ for Modules
2018.03.06:  ,
2018.05.02:
2018.10.08: , ,
n1736
headed for a TR
first implementation in Clang
n4047
Business Requirements for Modules
n4720
Another take on Modules p0924r0
Modules, Macros, and Build Systems
Merging Modules p1218r0 p1242r0 66
Modules - motivationModules - motivation
compile times...!!!
preprocessor includes led to:
leaked symbols & implementation details
name clashes
making tooling hard
workarounds (include guards)
include order matters
more DRY (don't repeat yourself)
forward declarations
code duplication in headers/sources
67
Modules - VS 2017 exampleModules - VS 2017 example
import std.core; // containers, algorithms, etc.
import M_1; // our module!
int main() {
std::vector<std::string> v = getStrings();
std::copy(v.begin(), v.end(),
std::ostream_iterator<std::string>(std::cout, "n"));
}
import std.core; // containers, string
export module M_1; // named M_1
export std::vector<std::string> getStrings() {
return {"Plato", "Descartes", "Bacon"};
}
cl.exe /experimental:module /EHsc /MD /std:c++latest /module:export /c mod_1
cl.exe /experimental:module /EHsc /MD /std:c++latest /module:reference M_1.ifc /c main.c
cl.exe main.obj mod_1.obj
68
Modules - how they workModules - how they work
BMI (Binary Module Interface) files
consumed by importers
produced by compiling a MIU (Module Interface Unit)
(maybe) contains serialized AST (abstract syntax tree)
with the exported parts of the parsed C++
unlike precompiled headers:
composability of multiple modules
explicit code annotations to define visible interfaces
69
Modules - obsolete techniquesModules - obsolete techniques
PIMPL!!! (mostly)
unless you need to provide ABI stability of your APIs
forward declarations (mostly)
precompiled headers
unity builds
70
Modules - the current stateModules - the current state
big companies are invested in them (think BIG)
there are 3 implementations already ( , , )
coming in C++20
when standardized and implemented in compilers:
do not expect astronomical gains in speed (for now)
build system support is hard
notably supports modules!
slow adoption in existing software
updating toolchains
source code changes
third party dependencies
if it ain't "broke" don't fix it
MSVC Clang GCC
build2
71
Next stepsNext steps
consider runtime C++ compilation & hotswap
make source control checkouts faster
tests
? please!!! it's great, trust me :)
ctest has -j N
Continuous integration
IDE integration of tools for better productivity
change language :| Nim is the anwser *cough*
http://bit.ly/runtime-compilation-alternatives
doctest
mtime_cache
72
Q&AQ&A
Slides:
Blog:
GitHub:
        :
E-Mail:
                               Other useful links:
https://slides.com/onqtam/faster_builds
http://onqtam.com
https://github.com/onqtam
https://twitter.com/KirilovVik
vik.kirilov@gmail.com
https://www.viva64.com/en/b/0549/
http://www.bitsnbites.eu/faster-c-builds/
https://github.com/green7ea/cpp-compilation
73

Weitere ähnliche Inhalte

Was ist angesagt?

Vim script と vimrc の正しい書き方@nagoya.vim #1
Vim script と vimrc の正しい書き方@nagoya.vim #1Vim script と vimrc の正しい書き方@nagoya.vim #1
Vim script と vimrc の正しい書き方@nagoya.vim #1cohama
 
Elixirと他言語の比較的紹介 ver.2
Elixirと他言語の比較的紹介ver.2Elixirと他言語の比較的紹介ver.2
Elixirと他言語の比較的紹介 ver.2Tsunenori Oohara
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linuxMazenetsolution
 
Yocto project and open embedded training
Yocto project and open embedded trainingYocto project and open embedded training
Yocto project and open embedded trainingH Ming
 
A general Overview of linux !!
A general Overview of linux !!A general Overview of linux !!
A general Overview of linux !!jainema23
 
Effective Linux Development Using PetaLinux Tools 2017.4
Effective Linux Development Using PetaLinux Tools 2017.4Effective Linux Development Using PetaLinux Tools 2017.4
Effective Linux Development Using PetaLinux Tools 2017.4Zach Pfeffer
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
コンテナネットワーキング(CNI)最前線
コンテナネットワーキング(CNI)最前線コンテナネットワーキング(CNI)最前線
コンテナネットワーキング(CNI)最前線Motonori Shindo
 
LLVM Backend Porting
LLVM Backend PortingLLVM Backend Porting
LLVM Backend PortingShiva Chen
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)Wang Hsiangkai
 
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)Drew Fustini
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototypingYan Vugenfirer
 
#logstudy 01 rsyslog入門
#logstudy 01 rsyslog入門#logstudy 01 rsyslog入門
#logstudy 01 rsyslog入門Takashi Takizawa
 

Was ist angesagt? (20)

Vim script と vimrc の正しい書き方@nagoya.vim #1
Vim script と vimrc の正しい書き方@nagoya.vim #1Vim script と vimrc の正しい書き方@nagoya.vim #1
Vim script と vimrc の正しい書き方@nagoya.vim #1
 
Elixirと他言語の比較的紹介 ver.2
Elixirと他言語の比較的紹介ver.2Elixirと他言語の比較的紹介ver.2
Elixirと他言語の比較的紹介 ver.2
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
 
Yocto project and open embedded training
Yocto project and open embedded trainingYocto project and open embedded training
Yocto project and open embedded training
 
Windows PowerShell
Windows PowerShellWindows PowerShell
Windows PowerShell
 
A general Overview of linux !!
A general Overview of linux !!A general Overview of linux !!
A general Overview of linux !!
 
Introduction git
Introduction gitIntroduction git
Introduction git
 
Effective Linux Development Using PetaLinux Tools 2017.4
Effective Linux Development Using PetaLinux Tools 2017.4Effective Linux Development Using PetaLinux Tools 2017.4
Effective Linux Development Using PetaLinux Tools 2017.4
 
from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
コンテナネットワーキング(CNI)最前線
コンテナネットワーキング(CNI)最前線コンテナネットワーキング(CNI)最前線
コンテナネットワーキング(CNI)最前線
 
LLVM Backend Porting
LLVM Backend PortingLLVM Backend Porting
LLVM Backend Porting
 
Scale Kubernetes to support 50000 services
Scale Kubernetes to support 50000 servicesScale Kubernetes to support 50000 services
Scale Kubernetes to support 50000 services
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)
 
Linux: LVM
Linux: LVMLinux: LVM
Linux: LVM
 
Linux Kernel Live Patching
Linux Kernel Live PatchingLinux Kernel Live Patching
Linux Kernel Live Patching
 
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
Linux on RISC-V with Open Source Hardware (Open Source Summit Japan 2020)
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
 
PFI Seminar 2010/02/18
PFI Seminar 2010/02/18PFI Seminar 2010/02/18
PFI Seminar 2010/02/18
 
#logstudy 01 rsyslog入門
#logstudy 01 rsyslog入門#logstudy 01 rsyslog入門
#logstudy 01 rsyslog入門
 
Debian Linux Overview
Debian Linux OverviewDebian Linux Overview
Debian Linux Overview
 

Ähnlich wie Faster C++ Builds with Precompiled Headers, Unity Builds and More

TestUpload
TestUploadTestUpload
TestUploadZarksaDS
 
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo OmuraPreferred Networks
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Eelco Visser
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentAdaCore
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxNEHARAJPUT239591
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJmeharikiros2
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfAnassElHousni
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docMayurWagh46
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applicationsRoman Podoliaka
 
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.jsTensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.jsStijn Decubber
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application DevelopmentRamesh Prasad
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVMJung Kim
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdfSteve Caron
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!Affan Syed
 
Source vs object code
Source vs object codeSource vs object code
Source vs object codeSana Ullah
 

Ähnlich wie Faster C++ Builds with Precompiled Headers, Unity Builds and More (20)

TestUpload
TestUploadTestUpload
TestUpload
 
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
20180926 kubeflow-meetup-1-kubeflow-operators-Preferred Networks-Shingo Omura
 
C++Basics2022.pptx
C++Basics2022.pptxC++Basics2022.pptx
C++Basics2022.pptx
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Bounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise EnvironmentBounded Model Checking for C Programs in an Enterprise Environment
Bounded Model Checking for C Programs in an Enterprise Environment
 
Introduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptxIntroduction-to-C-Part-1.pptx
Introduction-to-C-Part-1.pptx
 
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJIntroduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
Introduction-to-C-Part-1 JSAHSHAHSJAHSJAHSJHASJ
 
Introduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdfIntroduction-to-C-Part-1.pdf
Introduction-to-C-Part-1.pdf
 
Introduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).docIntroduction-to-C-Part-1 (1).doc
Introduction-to-C-Part-1 (1).doc
 
Debugging of (C)Python applications
Debugging of (C)Python applicationsDebugging of (C)Python applications
Debugging of (C)Python applications
 
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.jsTensorFlow meetup: Keras - Pytorch - TensorFlow.js
TensorFlow meetup: Keras - Pytorch - TensorFlow.js
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
Advance Android Application Development
Advance Android Application DevelopmentAdvance Android Application Development
Advance Android Application Development
 
C programming session9 -
C programming  session9 -C programming  session9 -
C programming session9 -
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Embedded C.pptx
Embedded C.pptxEmbedded C.pptx
Embedded C.pptx
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
 
ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!ebpf and IO Visor: The What, how, and what next!
ebpf and IO Visor: The What, how, and what next!
 
Source vs object code
Source vs object codeSource vs object code
Source vs object code
 

Mehr von corehard_by

C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...corehard_by
 
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...corehard_by
 
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений ОхотниковC++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотниковcorehard_by
 
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр ТитовC++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титовcorehard_by
 
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...corehard_by
 
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья ШишковC++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишковcorehard_by
 
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...corehard_by
 
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...corehard_by
 
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...corehard_by
 
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...corehard_by
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...corehard_by
 
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...corehard_by
 
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел ФилоновC++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филоновcorehard_by
 
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan ČukićC++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukićcorehard_by
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia KazakovaC++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakovacorehard_by
 
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон ПолухинC++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухинcorehard_by
 
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...corehard_by
 
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019corehard_by
 
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019corehard_by
 
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019corehard_by
 

Mehr von corehard_by (20)

C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
C++ CoreHard Autumn 2018. Создание пакетов для открытых библиотек через conan...
 
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
C++ CoreHard Autumn 2018. Что должен знать каждый C++ программист или Как про...
 
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений ОхотниковC++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
C++ CoreHard Autumn 2018. Actors vs CSP vs Tasks vs ... - Евгений Охотников
 
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр ТитовC++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
C++ CoreHard Autumn 2018. Знай свое "железо": иерархия памяти - Александр Титов
 
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
C++ CoreHard Autumn 2018. Информационная безопасность и разработка ПО - Евген...
 
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья ШишковC++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
C++ CoreHard Autumn 2018. Заглядываем под капот «Поясов по C++» - Илья Шишков
 
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
C++ CoreHard Autumn 2018. Ускорение сборки C++ проектов, способы и последстви...
 
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
C++ CoreHard Autumn 2018. Метаклассы: воплощаем мечты в реальность - Сергей С...
 
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
C++ CoreHard Autumn 2018. Что не умеет оптимизировать компилятор - Александр ...
 
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
C++ CoreHard Autumn 2018. Кодогенерация C++ кроссплатформенно. Продолжение - ...
 
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
C++ CoreHard Autumn 2018. Concurrency and Parallelism in C++17 and C++20/23 -...
 
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
C++ CoreHard Autumn 2018. Обработка списков на C++ в функциональном стиле - В...
 
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел ФилоновC++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
C++ Corehard Autumn 2018. Обучаем на Python, применяем на C++ - Павел Филонов
 
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan ČukićC++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
C++ CoreHard Autumn 2018. Asynchronous programming with ranges - Ivan Čukić
 
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia KazakovaC++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
C++ CoreHard Autumn 2018. Debug C++ Without Running - Anastasia Kazakova
 
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон ПолухинC++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
C++ CoreHard Autumn 2018. Полезный constexpr - Антон Полухин
 
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
C++ CoreHard Autumn 2018. Text Formatting For a Future Range-Based Standard L...
 
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
Исключительная модель памяти. Алексей Ткаченко ➠ CoreHard Autumn 2019
 
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019Как помочь и как помешать компилятору. Андрей Олейников ➠  CoreHard Autumn 2019
Как помочь и как помешать компилятору. Андрей Олейников ➠ CoreHard Autumn 2019
 
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019Автоматизируй это. Кирилл Тихонов ➠  CoreHard Autumn 2019
Автоматизируй это. Кирилл Тихонов ➠ CoreHard Autumn 2019
 

Kürzlich hochgeladen

Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditSkynet Technologies
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...panagenda
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality AssuranceInflectra
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 

Kürzlich hochgeladen (20)

Assure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyesAssure Ecommerce and Retail Operations Uptime with ThousandEyes
Assure Ecommerce and Retail Operations Uptime with ThousandEyes
 
Manual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance AuditManual 508 Accessibility Compliance Audit
Manual 508 Accessibility Compliance Audit
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
Why device, WIFI, and ISP insights are crucial to supporting remote Microsoft...
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance[Webinar] SpiraTest - Setting New Standards in Quality Assurance
[Webinar] SpiraTest - Setting New Standards in Quality Assurance
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 

Faster C++ Builds with Precompiled Headers, Unity Builds and More

  • 1. The Hitchhiker's Guide toThe Hitchhiker's Guide to FASTER BUILDSFASTER BUILDS by Viktor Kirilov 1
  • 2. Me, myself and IMe, myself and I my name is Viktor Kirilov - from Bulgaria 7+ years of professional C++ in the games / VFX industries worked only on open source for 3 years (2016-2019) creator of - the fastest C++ testing frameworkdoctest                     !!! not wasting time !!! Passionate about 2
  • 3. C++ is known for...C++ is known for... ▲ performance ▲ expressiveness ▲ being multi-paradigm ▼ complexity ▼ metaprogramming could be         much more powerful and simple ▼ no standard build system             and package management ▼ L0oo0oOoNG COMPILE TIMES 3
  • 4. Major C++ issue - compile timesMajor C++ issue - compile times 4
  • 5. This presentationThis presentation Introduction: WHAT and WHY precompiled headers unity builds hardware build systems caching distributed builds diagnostics static vs dynamic linkinglinkers PIMPL forward declarations includes templates binary bloat annotations modules parallel builds toolchains tooling 5 symbol visibility compilers Slides: https://slides.com/onqtam/faster_builds memes HOW
  • 6. RealityReality some projects take (tens of) hours to compile - WebKit: a big offender  both minimal and full rebuilds suffer more and more in time all projects start small - build times increase inevitably Opera 32 bit on Windows in 3 years 6 months: 15 minutes to 64+ + incorporated PCH !!! 6
  • 7. A unique problem to C++A unique problem to C++ Actually the folks at sympathize with us :DRust 7
  • 8. Why reduce build timesWhy reduce build times idle time is costly - lets do the math: assuming a 80k $ annual salary 1 hour daily for waiting (out of 8 hours: 12.5%) 10k $ per developer annually value to company > at least x3 the salary 100 developers ==> 3 million $ annually the unquantifiable effects of long build times discourage refactoring and experimentation lead to mental context switches (expensive) any time spent reducing build times is worthwhile !!! 8
  • 9. The steps in building C++ codeThe steps in building C++ code preprocessor: source file => translation unit includes macros, conditional compilation (ifdef) compiler: translation unit => object file parsing, tokens, AST optimizations code generation linker: object files & libraries => executable Absolutely fantastic explanation: https://github.com/green7ea/cpp-compilation 9
  • 10. Why C++ compilation takes so longWhy C++ compilation takes so long backwards compatibility with C: a killer feature ==> adoption!!! inherits the archaic textual include approach originally for sharing just declarations & structs between TUs language is complex (ADL, overloads, templates, etc.) multiple phases of translation - each depending on the previous not context independent new standards complicate things further complex zero-cost abstractions end up in headers even the preprocessor can become a bottleneck sub-optimal tools and build system setups bad project structure - component and header dependencies touch a header - rebuild everything 10
  • 11. C vs C++ and different standardsC vs C++ and different standards compiled as time increase C 5 sec baseline C++98 5.6 sec +12% C++11 5.6 sec +12% C++17 5.8 sec +14% compiled as time increase C++98 8.4 sec baseline C++11 9.8 sec +17% C++17 10.8 sec +29% C codebase (impl) https://github.com/vurtun/nuklear C++ codebase (impl + tests) (ver 1.2.8) https://github.com/onqtam/doctest Environment: GCC 7.2 on Windows, only compilation: "-c", in Debug: "-O0" optimizer doesn't care about language/standard: -O2 ==> same diff in seconds newer standards might be even heavier depending on the code more constexpr, metaclasses, concepts - further pressure on compilers constexpr - more complex compiler, but faster compile time algorithms 11
  • 12. That meme again...That meme again... 12
  • 13. Why includes suckWhy includes suck textual - not symbolic parsed results cannot be cached - macros... implementation dependencies are leaked/dragged privately used types by value need the definition the same code gets compiled many times the same headers end up used in many sources M headers with N source files ==> M x N build cost templates re-instantiated for the same types require more code to be in headers inline functions in headers (this includes templates) more work for the compiler/linker 13
  • 14. Standard includes - after the preprocessorStandard includes - after the preprocessor Header GCC 7 - size lines of code MSVC 2017 - size lines of code cstdlib 43 kb 1k 158 kb 11k cstdio 60 kb 1k 251 kb 12k iosfwd 80 kb 1.7k 482 kb 23k chrono 190 kb 6.6k 841 kb 31k variant 282 kb 10k 1.1 mb 43k vector 320 kb 13k 950 kb 45k algorithm 446 kb 16k 880 kb 41k string 500 kb 17k 1.1 mb 52k optional 660 kb 22k 967 kb 37k tuple 700 kb 23k 857 kb 33k map 700 kb 24k 980 kb 46k iostream 750 kb 26k 1.1 mb 52k memory 852 kb 29k 1.0 mb 40k random 1.1 mb 37k 1.4 mb 67k functional 1.2 mb 42k 1.4 mb 58k regex 1.7 mb 64k 1.5 mb 71k ALL OF THEM 2.6mb 95k 2.3mb 98k 14
  • 15. Boost includes - after the preprocessorBoost includes - after the preprocessor Header GCC 7 - size lines of code MSVC 2017 - size lines of code hana 857 kb 24k 1.5 mb 69k optional 1.6 mb 50k 2.2 mb 90k variant 2 mb 65k 2.5 mb 124k function 2 mb 68k 2.6 mb 118k format 2.3 mb 75k 3.2 mb 158k signals2 3.7 mb 120k 4.7 mb 250k thread 5.8 mb 188k 4.8 mb 304k asio 5.9 mb 194k 7.6 mb 513k wave 6.5 mb 213k 6.7 mb 454k spirit 6.6 mb 207k 7.8 mb 563k geometry 9.6 mb 295k 9.8 mb 448k ALL OF THEM 18 mb 560k 16 mb 975k environment: C++17, GCC 7, VS 2017, Boost version: 1.66 100 .cpp files including geometry ==> 1 GB of source code! not meant to discredit Boost - this is a C++ issue 15
  • 16. Insert title of slideInsert title of slide 16
  • 17. GCC/Clang warning: -Wunused, -Wunused-function -ffunction/data-sections -Wl,--gc-sections,--print-gc-sections  --enable=unusedFunction  - DEADCODE/UNREACHABLE  by scitools  - static and dynamic ... also runtime coverage ( (& lcov for GUI), others) cppcheck Coverity Understand CppDepend PVS Studio OCLint Parasoft C/C++ Test Polyspace oovcde dead code detection others gcov Unreachable (dead) codeUnreachable (dead) code The C++ philosophy: "don't pay for what you don't use" might also uncover bugs & improve runtime! 17
  • 18. compile in Debug instead of Release if feasible -O0, -O1, -O2, -O3, -Os - different results! unused sources/libraries look for such after dead code removal often a problem with makefiles and old cruft MSVC warning LNK4221: This object file does not define any previously undefined public symbols compile each source file just once scan the build logs for such instances commonly used sources => static libraries Other low hanging fruitOther low hanging fruit 18
  • 19. strive for loose coupling specific includes is better than #include "everything.h" more granular rebuilds when touching headers  - the most popular (Clang-based)   (or the ) -  << also has a test runner for doctest!  - plugin for Eclipse CDT (or the ) ProFactor IncludeManager - MSVC: /showIncludes      GCC: -H https://include-what-you-use.org/ Doxygen + Graphviz https://github.com/myint/cppclean Header Hero fork article https://github.com/tomtom-international/cpp-dependencies ReSharper C++ Includes Analyzer Includator Cevelop IDE https://gitlab.com/esr/deheader https://www.profactor.co.uk/ Finding unnecessary includesFinding unnecessary includes find_program(iwyu_path NAMES include-what-you-use iwyu) set_property(TARGET hello PROPERTY CXX_INCLUDE_WHAT_YOU_USE ${iwyu_path}) 19
  • 20. Declarations vs definitions - functionsDeclarations vs definitions - functions // interface.h int foo(); // fwd decl - definition is in a source file somewhere inline int bar() { // needs to be inline if the body is in a header return 42; } struct my_type { int method { return 666; } // implicitly inline - can get inlined! }; template <typename T> // a template - "usually" has to be in a header T identity(T in) { return in; } // implicitly inline move function definitions out of headers builds will be faster use link time optimizations for inlining (or unity builds!) some optimizations for templates exist - in later slides 20
  • 21. Declarations vs definitions - typesDeclarations vs definitions - types // interface.h #pragma once struct foo; // fwd decl - don't #include "foo.h"! #include "bar.h" // drag the definition of bar struct my_type { foo f_1(foo obj); // fwd decl used by value in signature - OK foo* foo_ptr; // fwd decl used as pointer - OK bar member; // requires the definition of bar }; // interface.cpp #include "interface.h" #include "foo.h" // drag the definition of foo foo my_type::f_1(foo obj) { return obj; } // needs the definition of f 21
  • 22. used by value including in class definitions (size for memory layout) not in function declarations !!!   types are used by reference/pointer pointer size is known by the compiler (4/8 bytes) compiler doesn't need to know the size of types types are used by value in function declarations either as a return type or as an argument this is less known !!! function definition will still need the full type definition call site also needs the full type definition Declarations vs definitions - typesDeclarations vs definitions - types definition of types is necessary only when they are: forward declarations are enough if: 22
  • 23. PIMPL - pointer to implementationPIMPL - pointer to implementation AKA compilation firewall holds a pointer to the implementation type // widget.h struct widget { widget(); ~widget(); // cannot be defaulted here void foo(); private: struct impl; // just a fwd decl std::unique_ptr<impl> m_impl; }; // widget.cpp struct widget::impl { void foo() {} }; widget::widget() : m_impl(std::make_unique<widget::impl>()) {} widget::~widget() = default; // here it is possible void widget::foo() { m_impl->foo(); } 23
  • 24. PIMPL - pros & consPIMPL - pros & cons breaks the interface/implementation dependency less dragged headers ==> better compile times! implementation data members no longer affect the size helps with preserving ABI when changing the implementation lots of APIs use it (example: Autodesk Maya)   requires allocation, also space overhead for pointer can use allocators extra indirection of calls - link time optimizations can help more code PROS: CONS: on const propagation, moves, copies and other details: http://en.cppreference.com/w/cpp/language/pimpl 24
  • 25. Abstract interfaces & factoriesAbstract interfaces & factories // interface.cpp #include "interface.h" // implementation 1 struct Derived_1 : public IBase { int data; Derived_1(int in) : data(in) {} int do_stuff() override { return data; } }; // implementation 2 struct Derived_2 : public IBase { int do_stuff() override { return 42; } }; // factory functions std::unique_ptr<IBase> make_der_1(int in) { return std::make_unique<Derived_1>(in); } std::unique_ptr<IBase> make_der_2() { return std::make_unique<Derived_2>(); } // interface.h struct IBase { virtual int do_stuff() = 0; virtual ~IBase() = default; }; // factory functions std::unique_ptr<IBase> make_der_1(int); std::unique_ptr<IBase> make_der_2(); Implementations of derived classes are obtained through factory functions 25
  • 26. Abstract interfaces & factoriesAbstract interfaces & factories breaks the interface/implementation dependency helps with preserving ABI (careful with the virtual interface)     requires allocation, also space overhead for pointer extra indirection of calls (virtual) more code users work with (smart) pointers instead of values link time optimizations - harder than for PIMPL PROS: CONS: 26
  • 27. Precompiled headersPrecompiled headers put headers that are used in many of the sources put headers that don't change often do regular audits to reflect the latest project needs often disregarded as a hack by many - HUGE mistake IMHO easy setup and benefits can be huge // precompiled.h #pragma once // system, runtime, STL #include <cstdio> #include <vector> #include <map> // third-party #include <dynamix/dynamix.hpp> #include <doctest.h> // rarely changing project-specific #include "utils/singleton.h" #include "utils/transform.h" 27
  • 28. Precompiled headers - usagePrecompiled headers - usage supported by mainstream compilers MSVC: "/Yc" & "/Yu" GCC/Clang: "-x c++-header" only one PCH per translation unit :( force-include for convenience /FI (MSVC) or -include (GCC/Clang) build system support (native) (native)  (native) CMake - with modules Meson Buck FASTBuild cotire cmake-precompiled-header 28
  • 29. AKA: amalgamated, jumbo, SCU include all original source files in one (or a few) unity source file(s) Unity buildsUnity builds // unity file #include "core.cpp" #include "widget.cpp" #include "gui.cpp" headers get parsed only once if included from multiple sources less compiler invocations less instantiation of the same templates HIGHLY underrated NOT because of reduced disk I/O - filesystems cache aggressively less linker work used at Ubisoft (14+ years), Unreal, WebKit The main benefit is compile times: 29
  • 30. up to 10+ times faster (depends on modularity) best gains: short sources + lots of includes faster (and not slower) LTO (WPO/LTCG) ODR (One Definition Rule) violations get caught this one is huge - still no reliable tools . .   enforces code hygiene include guards in headers no statics and anon namespaces in headers less copy/paste of types & inline functions Unity builds - prosUnity builds - pros // a.cpp struct Foo { // implicit inline int method() { return 42; } }; // b.cpp struct Foo { // implicit inline int method() { return 666; } }; 30
  • 31. might slow down some workflows minimal rebuilds might interfere with parallel compilation these ^^ can be solved with tuning/configuring some C++ stops compiling as a unity clashes of symbols in anonymous namespaces overload ambiguities using namespaces in sources preprocessor miscompilation - rare (but possible) successful compilation with a wrong result preprocessor, overloads (also non-explicit 1 arg constructors) good tests can help! Unity builds - consUnity builds - cons 31
  • 32.  (as a CMake module, there are others) (build system) experimental support for Unity builds   can produce multiple unity source files can exclude files (if problematic, or for incremental builds)   (build system) (build system) (Visual Studio extension) custom solution cotire FASTBuild Visual Studio Meson waf RudeBuild Unity builds - how to maintainUnity builds - how to maintain these: others: 32
  • 33. __declspec(noinline) / __attribute__((noinline)) and careful with __forceinline / __attribute__((always_inline)) leads to compile time savings might even help with runtime (instruction cache bloat) implicit culprit: destructors especially for heavily repeated constructs asserts in testing frameworks example: - "The fastest feature-rich C++11 single- header testing framework" doctest CppCon 2017: Viktor Kirilov "Mix Tests and Production Code With Doctest - Implementation and usage" Inlining annotationsInlining annotations explicitly disable inlining: 33
  • 34. linkers sometimes can fold identical functions - but more work only if proven you aren't taking their addresses (required by the standard) this way: less work for the compiler/linker now it is syntactically easier to move function bodies out of the header use link time optimizations for inlining (or unity builds!) Templates - argument-independent codeTemplates - argument-independent code template <typename T> class my_vector { int m_size; // ... public: int size() const { return m_size; } // ... }; // my_vector<T>::size() is instantiated // for types such as int, char, etc... // even though it doesn't depend on T class my_vector_base { // type independent protected: // code is moved out int m_size; public: int size() const { return m_size; } }; template <typename T> // type dependent class my_vector : public my_vector_base { // ... public: // ... }; 34
  • 35. Templates - C++11 extern templateTemplates - C++11 extern template // interface.h #include <vector> template <typename T> T identity(T in) { return in; } // somewhere.cpp #include "interface.h" // do not instantiate these templates here extern template int identity<int>(int); extern template float identity<float>(float); extern template class std::vector<int>; // will not instantiate auto g_int = identity(5); auto g_float = identity(15.f); std::vector<int> a; // will instantiate for bool auto g_unsigned = identity(true); no instantiation/codegen where extern-ed but still has to be parsed... precompiled headers or unity builds !!!! some STL implementations do it for std::basic_string<char, ...> https://arne-mertz.de/2019/02/extern-template-reduce-compile-times/ // somewhere_else.cpp #include "interface.h" // instantiation for float template float identity<float>(float); // instantiation for std::vector<int> template class std::vector<int>; // instantiation for identity<int>() auto g_int_2 = identity(1); 35
  • 36. the class/function has to be explicitly instantiated somewhere for all types it is used with... or linker errors! Templates - move functions out of headersTemplates - move functions out of headers // interface.h // declaration template <typename T> T identity(T in); template <typename T> struct answer { // declaration T calculate(); }; // interface.cpp #include "interface.h" // definition template <typename T> T identity(T in) { return in; } // definition template <typename T> T answer<T>::calculate() { return T(42); } // explicit instantiations for int/float template int identity<int>(int); template float identity<float>(float); // explicit instantiation for int template struct answer<int>; // user.cpp #include "interface.h" auto g_int = identity(666); auto g_float = identity(0.541f); auto g_answer = answer<int>().calculate(); 36
  • 37. The "Rule of ": 1. looking up a memoized type 2. adding a parameter to an alias call 3. adding a parameter to a type 4. calling an alias 5. instantiating a type 6. instantiating a function template 7. SFINAE Chiel Templates - cost of operationsTemplates - cost of operations A fascinating talk: code::dive 2017 – Odin Holmes – The fastest template metaprogramming in the West 37
  • 38. use variadic templates sparingly recursive templates are bad business especially when not memoized recursive template arguments are even worse now that we have "constexpr if" we can use a lot less SFINAE if constexpr might be preferrable even to tag dispatching Templates - other notesTemplates - other notes 38
  • 39.  - interactive template metaprogramming shell Clang-based GUI: Clang-based profile time/memory consumption of template instantiations interactive debugging sessions IDE (Eclipse CDT based) - Template Visualization metashell https://github.com/RangelReale/msgui https://github.com/mikael-s-persson/templight https://github.com/mikael-s-persson/templight-tools Cevelop Templates - toolsTemplates - tools 39
  • 40. reducing compile times of -generated code: type tags to circumvent SFINAE and use overload resolution diagnostics -ftime-report - breakdown of time spent in compiler phases templight  - Alternative title: "Boost your TMP-Fu" metaprogramming through composition builds onto his previous talk brigand, kvasir, metal, mp11 - CppCon 2017: Eddie Elizondo “Optimizing compilation times with Templates” Thrift C++Now 2018: Odin Holmes “Boost.TMP: Your DSL for Metaprogramming” http://metaben.ch/ Templates - other good talksTemplates - other good talks 40
  • 41. -ftime-report - breakdown of different compiler phases -ftime-trace (Clang) - - by Aras Pranckevičius   /Bt - frontend & backend (optimizer/codegen) /time - for the linker /d2cgsummary - Anomalistic Compile Times for functions first advertised by Aras Pranckevičius - /d1reportTime - includes, classes, functions - times - /d1templateStats thanks to these flags Chrome tracing flamegraph "Best-unknown-MSVC-flag" blog post surprising 1 line fix => 20% faster builds Updating VS 2017 15.6 to 15.8 => 2x slower for template instantiations Diagnostics - compilationDiagnostics - compilation some functions trigger pathological cases (or bugs) in compilers/optimizers Clang/GCC: MSVC: 41
  • 42. Bloaty McBloatface: a size profiler for ELF/Mach-O binaries Sizer: Win32/64 executable size report utility SymbolSort: measuring C++ code bloat in Windows binaries twiggy: call graph analyzer (wasm only, no ELF/Mach-O/PE/COFF yet) nm - Unix tool to inspect the symbol table of binaries nm --print-size --size-sort --demangle --radix=d YOUR_BINARY dumpbin: Microsoft COFF Binary File Dumper common culprit: templates (because length of names matters!!!) demangling: undname.exe / c++filt / https://github.com/google/bloaty https://github.com/aras-p/sizer https://github.com/adrianstone55/SymbolSort https://github.com/rustwasm/twiggy https://demangler.com Diagnostics - binary bloatDiagnostics - binary bloat 42
  • 44. Build systemsBuild systems "g++ src1.cpp src2.cpp ..."  is not a build system dependency tracking - for minimal and parallel rebuilds help managing scale includes, flags, link libs help with refactoring/restructuring help with tool integration not all are created equal HUGE topic (trade-offs, approaches) - but lets focus just on speed most old build systems have high overhead (MSBuild, make) suboptimal dependency and change detection/scanning 44
  • 45. Parallel buildsParallel builds Ninja, FASTBuild, IncrediBuild: best in this regard make: -jN (and through CMake: "cmake --build . -- -jN") MSBuild (build system behind Visual Studio): /MP[processMax] - in CMake: "target_compile_options(target /MP)" inability to parallelize compilation of dependent dlls  fixes this when integrated with Visual Studio thread oversubscription (no overarching scheduler): 8 projects in parallel (8 cpp each + /MP) ==> 64 threads! Ninja instead of MSBuild as the VS backend! since recently supports  - Bruce Dawson careful with unity builds and "long poles" modern LTO/LTCG technology is parallelizable too IncrediBuild running Custom Build Tools in parallel Make VC++ Compiles Fast Through Parallel Compilation 45
  • 46. Diagnosing/monitoring parallelismDiagnosing/monitoring parallelism  - Bruce DawsonMake VC++ Compiles Fast Through Parallel Compilation 46
  • 48. Diagnosing/monitoring parallelismDiagnosing/monitoring parallelism Chrome's  (flame graph) - chrome://tracing/about:tracing build system not related to parallelism, but for -ftime-trace in clang: ninjatracing buck blog post llvm mailing list other blog post 48
  • 49. Sort-of winners (in terms of speed)Sort-of winners (in terms of speed) FASTBuild unity builds precompiled headers caching distributed builds best parallelization generates project files multiplatform multi-compiler tiny might get a CMake backend others... haven't looked into these yet buck << by Facebook bazel << by Google build2 << modules! :D meson << hot contender ... Ninja - less features but crazy fast - intented to be generated by a meta-build system GN (GYP replacement) can generate ONLY ninja IndrediBuild tup 49
  • 50. big discussion overall - but here we care about build times much much faster - handles only the exported interface Static vs dynamic linkingStatic vs dynamic linking prefer dynamic (.dll, .so, .dylib) over static (.lib, .a) 50
  • 51. Unix: all symbols exported by default opposite to Windows - which got the default right! UNIX: compile with -fvisibility=hidden improves link time annotate the required parts of the API for exporting circumvents the GOT (Global Offset Table) for calls => profit load times also improved (extreme templates case: 45 times) reduces the size of your DSO by 5-20% for details: clang-cl on windows: => 30% faster chrome build alternative: -fvisibility-inlines-hidden all inlined member functions are hidden no source code modifications needed careful with local statics in inline functions can also explicitly annotate with default visibility https://gcc.gnu.org/wiki/Visibility /Zc:dllexportInlines- Dynamic linking - symbol visibilityDynamic linking - symbol visibility 51
  • 52. Multiplatform symbol export annotationsMultiplatform symbol export annotations #if defined _WIN32 || defined __CYGWIN__ #define SYMBOL_EXPORT __declspec(dllexport) #define SYMBOL_IMPORT __declspec(dllimport) #define SYMBOL_HIDDEN #else #define SYMBOL_EXPORT __attribute__((visibility("default"))) #define SYMBOL_IMPORT #define SYMBOL_HIDDEN __attribute__((visibility("hidden"))) #endif #ifdef DLL_EXPORTS // on this depends if we are exporting or importing #define MY_API SYMBOL_EXPORT #else #define MY_API SYMBOL_IMPORT #endif MY_API void foo(); class MY_API MyClass { int c; SYMBOL_HIDDEN void privateMethod(); // only for use within this DSO public: MyClass(int _c) : c(_c) { } static void foo(int a); }; 52
  • 53. LinkersLinkers gold (unix) comes with binutils starting from version 2.19 -fuse-ld=gold not threaded by default configure with "--enable-threads" use: "--threads", "--thread-count COUNT", "--preread-archive-symbols" lld even faster than gold - - multithreaded by default Unix: Split DWARF -  - building clang/llvm codebase 10%+ faster full builds and 40%+ faster incremental builds CMake - https://lld.llvm.org/ article LINK_WHAT_YOU_USE 53
  • 54. Linkers - LTO and other flagsLinkers - LTO and other flags clang ThinLTO: MSVC - lots of improvements, also regarding LTCG lots of improvements in the recent years /debug:fastlink – generate partial PDB (new format) /INCREMENTAL for debug VS 2019 - LTCG /LTCG:incremental also parallel - /cgthreads:8 instead of the default 4 CppCon 2017: Teresa Johnson “ThinLTO: Scalable and Incremental Link- Time Optimization” GCC 8: link time and interprocedural optimization Visual Studio 2017 Throughput Improvements and Advice Speeding up the Incremental Developer Build Scenario from x1.4 to x1.75 faster link times for Chrome with VS 2019 huge speedups (~x2) 54
  • 55. Compiler cachesCompiler caches "compiler wrapper" - maps a hash of: preprocessed source (TU) compilation flags & compiler version ==> to an object file First run (cold cache) is a bit slower than without the wrapper Consecutive >> FULL << rebuilds are much faster (warm cache) 55
  • 56. Compiler cachesCompiler caches For Unix alike:  (GCC, Clang),  (GCC) For Windows:  (MSVC),  (MSVC)  - straight out of the build system!  (GCC, Clang, MSVC) ccache with cloud storage over AWS S3/GCS/Redis  (MSVC) also distributed & with cloud storage  - a Clang fork - not a wrapper! - in memory caching server for requested compilations biggest gains on heavy templates - recently  - future not clear x2~x5 times faster - ccache cachecc1 clcache cclash http://fastbuild.org/ https://github.com/mozilla/sccache https://stashed.io/ zapcc mail thread article open-sourced WebKit can compile more benchmarks 56
  • 57. Compiler cachesCompiler caches caches work best for full rebuilds - not minimal Other links: Faster C++ builds Speeding up the Build of C and C++ Projects ccache and CMake:       Using ccache with CMake Speed up C++ compilation, part 2: compiler cache find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}") endif() project(SomeProject) 57
  • 58. Distributed buildsDistributed builds take advantage of unused processing power of computers prepend in front of compiler just like caches: distcc gcc ... caching + distributed builds = ❤ , and   watch out: network bottlenecks include directories - sort em! bandwidth here here here OMG again that build system!!! ==> some article: https://github.com/distcc/distcc https://github.com/icecc/icecream https://www.incredibuild.com/ http://fastbuild.org/ Speed up C++ compilation, part 3: distributed compilation export CCACHE_PREFIX=DISTCC 58
  • 60. HardwareHardware more cores make sure you have enough RAM && parallel builds setup RAM disks (file system drive in your RAM instead of ssd/hdd) better than SSDs don't expect huge gains though... mount $TEMP as a RAM disk (%TEMP% for windows) build output to RAM disk (most important - because of the link step) also put the compiler there! touches on network I/O issues and many other topics CppCon 2014: Matt Hargett "Common-sense acceleration of your MLOC build" 60
  • 61. What if the fundament is badWhat if the fundament is bad 61
  • 62. Physical designPhysical design physical structure/design often neglected every project starts small... some end up big and it's too late reasoning about components and modularity - IMPORTANT!!! physically (and logically): files, dependencies, includes benefits: fast builds, easy to reason, easy to refactor Article: John Lakos (Bloomberg) book: multi-part talk: "Advanced Levelization Techniques" Controversial article: Physical Structure and C++ - A First Look "Large-scale C++ Software Design" C++Now 2018: “C++ Modules & Large-Scale Development” Physical Design of The Machinery 62
  • 63. Dependency analysisDependency analysis cmake --graphviz=[file] visualize with some (most) build systems have such a feature ( ) Most tools from the "Finding unnecessary includes" slide by scitools - Graphviz - Graphviz maybe even IDE tools options Graphviz bazel Understand CppDepend cpp-dependencies Doxygen SourceTrail Visual Studio Code Maps 63
  • 64. Dependency analysisDependency analysis Boost.Variant - - by Stephen KellyBoost dependencies and bcp Boost.Spirit Boost.Geometry 64
  • 66. Modules - historyModules - history 2004.11.05: first proposal: - Modules in C++ by Daveed Vandevoorde - working on EDG - the only compiler supporting exported templates (and aiding in their deprecation) dropped from C++11 after a few revisions ==> 2011: work on - by Douglas Gregor 2014.05.27: standardization continues with - A Module System for C++ by Gabriel Dos Reis, Mark Hall and Gor Nishanov after a few revisions - didn't enter C++17 - left as a TS latest work: will enter C++20 2017.06.16: 2018.01.29: - Working Draft, Extensions to C++ for Modules 2018.03.06:  , 2018.05.02: 2018.10.08: , , n1736 headed for a TR first implementation in Clang n4047 Business Requirements for Modules n4720 Another take on Modules p0924r0 Modules, Macros, and Build Systems Merging Modules p1218r0 p1242r0 66
  • 67. Modules - motivationModules - motivation compile times...!!! preprocessor includes led to: leaked symbols & implementation details name clashes making tooling hard workarounds (include guards) include order matters more DRY (don't repeat yourself) forward declarations code duplication in headers/sources 67
  • 68. Modules - VS 2017 exampleModules - VS 2017 example import std.core; // containers, algorithms, etc. import M_1; // our module! int main() { std::vector<std::string> v = getStrings(); std::copy(v.begin(), v.end(), std::ostream_iterator<std::string>(std::cout, "n")); } import std.core; // containers, string export module M_1; // named M_1 export std::vector<std::string> getStrings() { return {"Plato", "Descartes", "Bacon"}; } cl.exe /experimental:module /EHsc /MD /std:c++latest /module:export /c mod_1 cl.exe /experimental:module /EHsc /MD /std:c++latest /module:reference M_1.ifc /c main.c cl.exe main.obj mod_1.obj 68
  • 69. Modules - how they workModules - how they work BMI (Binary Module Interface) files consumed by importers produced by compiling a MIU (Module Interface Unit) (maybe) contains serialized AST (abstract syntax tree) with the exported parts of the parsed C++ unlike precompiled headers: composability of multiple modules explicit code annotations to define visible interfaces 69
  • 70. Modules - obsolete techniquesModules - obsolete techniques PIMPL!!! (mostly) unless you need to provide ABI stability of your APIs forward declarations (mostly) precompiled headers unity builds 70
  • 71. Modules - the current stateModules - the current state big companies are invested in them (think BIG) there are 3 implementations already ( , , ) coming in C++20 when standardized and implemented in compilers: do not expect astronomical gains in speed (for now) build system support is hard notably supports modules! slow adoption in existing software updating toolchains source code changes third party dependencies if it ain't "broke" don't fix it MSVC Clang GCC build2 71
  • 72. Next stepsNext steps consider runtime C++ compilation & hotswap make source control checkouts faster tests ? please!!! it's great, trust me :) ctest has -j N Continuous integration IDE integration of tools for better productivity change language :| Nim is the anwser *cough* http://bit.ly/runtime-compilation-alternatives doctest mtime_cache 72
  • 73. Q&AQ&A Slides: Blog: GitHub:         : E-Mail:                                Other useful links: https://slides.com/onqtam/faster_builds http://onqtam.com https://github.com/onqtam https://twitter.com/KirilovVik vik.kirilov@gmail.com https://www.viva64.com/en/b/0549/ http://www.bitsnbites.eu/faster-c-builds/ https://github.com/green7ea/cpp-compilation 73