+ All Categories
Home > Software > Alexander Kutsan: “C++ compilation boost”

Alexander Kutsan: “C++ compilation boost”

Date post: 10-Jan-2017
Category:
Upload: logeeknightukraine
View: 44 times
Download: 3 times
Share this document with a friend
19
www.luxoft.com C++ compilation boost Last update 12 Oct 2016
Transcript
Page 1: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

C++ compilation boost

Last update 12 Oct 2016

Page 2: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

Compilation is verry long in C++

Page 3: Alexander Kutsan: “C++ compilation boost”

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

Page 4: Alexander Kutsan: “C++ compilation boost”

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.

Page 5: Alexander Kutsan: “C++ compilation boost”

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.

Page 6: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

How c++ make executable from source files?

File_1.cc

File_2.cc

File_N.ccmain.cc

…Magic Executable

Page 7: Alexander Kutsan: “C++ compilation boost”

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

Page 8: Alexander Kutsan: “C++ compilation boost”

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

Page 9: Alexander Kutsan: “C++ compilation boost”

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

Page 10: Alexander Kutsan: “C++ compilation boost”

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)

Page 11: Alexander Kutsan: “C++ compilation boost”

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.

Page 12: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

Good ideas are around us

Page 13: Alexander Kutsan: “C++ compilation boost”

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

Page 14: Alexander Kutsan: “C++ compilation boost”

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

Page 15: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

Statistics with distcc

statistics

Page 16: Alexander Kutsan: “C++ compilation boost”

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

Page 17: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

Statistics with ccache

statistics

Page 18: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

Some final statistics

statisticsProject : https://github.com/smartdevicelink/sdl_core/

Page 19: Alexander Kutsan: “C++ compilation boost”

www.luxoft.com

THANK YOUAlexander KutsanEmail : [email protected] work: LuxoftAKutsanGithub personal : alexkutsan


Recommended