Automatic Refactoring and Compile Time Optimization of Cpp Projects by Directly Including Header Files

Julian Reisch, Peter J. Grossmann · 2022

The compilation of a project from source to machine code can take up to hours of computation time which in large part depends on how many lines of code are compiled. In the programming language C++, source code is written in separate header and source files. The code in a header file is compiled in each source file it is included in. In order to minimize the compilation time of the project, code should therefore be included only in source files where it is actually used. We present an optimization model that minimizes the number of lines of code that are included and hence compiled but not used. The restrictions of the model are the dependencies in the code. For example, when a function is called in a source file, the header file where this function is defined in must be included in the source file. The variables of the model are which file includes which other files. We propose the solution method to replace indirect includes by more direct ones. We provide computational results on read-world C++ projects and show that the compilation times can be reduced by up to 9%.

Read the paper · More papers on PaperTik