Skip to content

[FEATURE] Optimize compilation speed by reorganize headers #486

@TonyXiang8787

Description

@TonyXiang8787

Introduction

The calculation core is a header-only library in C++. In each build target of unit test, C API, validation test, etc, we have multiple translation units (.cpp files). The compilation speed is slow in both CI and local development machine. This is frustrating and slows down the development.

Proposal

We would like to re-organize the headers in the header only library to reduce the dependencies between the headers. Hopefully we can increase the compilation speed. Possible ways of improvement can be:

  1. Remove most of the standard library include in the main file power_grid_model.hpp. Only keep the absolute common standard libraries (like cstddef). Include the needed standard library in individual header files where it is needed.
  2. Forward declare classes in the main file power_grid_model.hpp, so that other headers can use the opaque type if the full type is not needed. This reduces the dependencies between the headers.
  3. Use separate header file with type_traits types to specify the input, update, .. types of each component. In this way, when compiling meta-data (like serializer), we do not need to include all the component types, only the traiter types.
  4. Make the MathSolver a generic template class with supported solvers, just like how the MainModelImpl is templated with the components
  5. Move generic template class using declarations like using MainModel = MainModelImpl<...>; to separate header files, e.g. main_model.hpp and main_model_impl.hpp. The tester of dispatch functionality of the MainModel could then use a component-less instance.

Metadata

Metadata

Assignees

No one assigned

    Labels

    improvementImprovement on internal implementation

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions