Date post: | 10-Jan-2017 |
Category: |
Software |
Upload: | logeeknightukraine |
View: | 44 times |
Download: | 3 times |
www.luxoft.com
C++ compilation boost
Last update 12 Oct 2016
www.luxoft.com
Compilation is verry long in C++
www.luxoft.com
Stages of problem understanding
Negation ( C++ compilation is no slow) Reasons (compilation is slow because runtime is very fast) Transfer responcibility on C (backward capability) Adoption and finding ways to change the situation. Time is money
www.luxoft.com
Project
Open source C++ code base About 20 developers team Cross platform (Linux, QNX, Windows, Qt)
SmartDeviceLink https://github.com/smartdevicelink/sdl_core/
SmartDeviceLink (SDL) is a standard set of protocols and messages that connect applications on a smartphone to a vehicle head unit.
www.luxoft.com
Why long compilation is bad?
Spent developers time Diffusion of developers attention Destruction of nerves
Situation 1:9:00 pm. Release, hotfix is ready, but processes does not allow to provide it before build server won’t compile code, run unit tests, collect coverage, analyse with static code analysys tools. Situation 2:Developer know that project builds ~ 1h. He trigger build and go to the meating/dinner/coffe… But due to compilation errors it stops in 10 minutes. After 1 hour developer see it and upset.
www.luxoft.com
How c++ make executable from source files?
File_1.cc
File_2.cc
File_N.ccmain.cc
…Magic Executable
www.luxoft.com
How c++ make executable from source files?
File_1.cc
File_2.cc
File_N.cc
main.cc
… Executable
File_1.cc
File_2.cc
File_N.cc
…
File_1.o
File_2.o
File_N.o
…
main.cc main.o
Linker
www.luxoft.com
Components segmentation
File_1.cc
File_2.cc
File_N.cc
main.cc
…
Executable
File_1.cc
File_2.cc
File_N.cc
…
main.cc
Component_1 Component_2 Component_3
LinkageLinkage
www.luxoft.com
Parallel build
Time
Cores
Build file1.cc Build file5.cc
Build file2.cc
Build file3.cc
Build file4.cc
Link component 1
Link component2
Link component 3 Link Executable
www.luxoft.com
Parallel build
Problem + Multithreading = Multiproblems Components dependencies
Code generation dependencies Optimal count of jobs Parsing compiler error’s output Multithreaded build blocks work on slow worstations Unable to run multithreaded build on public build servers (Travis)
www.luxoft.com
Build is still to slowSmall tips for developers for fast build and good project health
Do not store any logic in headers Avoid abuse of templates and metaprogramming. Follow SOLID principles Lookup that each *.cc file compiles only ones. Keep build dirrectory on RAM disk (tmpfs) Build project in a background in low priority during
editing Avoid a lot of #ifdefs (use strategy pattern) Avoid creating special methods that are available in
UT mode.
www.luxoft.com
Good ideas are around us
www.luxoft.com
Distributed buildWS1WS1 WS1WS2 WS1WS3 WS1WS4
Send file1.ccSend file2.cc
Send file3.cc
Compile Compile Compile Compile
Send file1.oSend file2.o
Send file3.o
Link
www.luxoft.com
Distributed build
Problem + distributed multithreading
= distributed multiproblems Network latency
Unification of environment Hold and sync list of workstations withat are able to take part in distributed build Performance issues on all workstations during build
www.luxoft.com
Statistics with distcc
statistics
www.luxoft.com
Can we do better?CCache
Cache build results. do not need to rebuild already builded binaries Easy to use and integrate in project
Usage in the wild:
$ ccache g++ file.cc -o output
Usage with cmake:
$ cmake ../ -DUSE_CCACHE
www.luxoft.com
Statistics with ccache
statistics
www.luxoft.com
Some final statistics
statisticsProject : https://github.com/smartdevicelink/sdl_core/
www.luxoft.com
THANK YOUAlexander KutsanEmail : [email protected] work: LuxoftAKutsanGithub personal : alexkutsan