Skip to content

[cmake] Optimize compilation performances#241

Open
Me-k-01 wants to merge 29 commits intoponcateam:masterfrom
Me-k-01:precompiled-headers
Open

[cmake] Optimize compilation performances#241
Me-k-01 wants to merge 29 commits intoponcateam:masterfrom
Me-k-01:precompiled-headers

Conversation

@Me-k-01
Copy link
Copy Markdown
Collaborator

@Me-k-01 Me-k-01 commented Dec 18, 2025

Fix issue #235

This PR aims to add precompiled headers to the Fitting and the SpatialPartitioning module, to accelerate the build time on the CI.

This module uses precompiled header parsing and explicit template instantiation to accelerate the total build time of multiple compile target (like the CI tests, or the code coverage test)

Changes made by this PR

  • Add PCH to Fitting containing all of the commonly used fitting types (a new lib and target must be added in the cmake)
  • Use Explicit instantiation to instantiate commonly used Fitting class in the CI test  
  • Add PCH to SpatialPartitioning for the commonly used KdTree and KnnGraph
  • Use Explicit instantiation to instantiate commonly used SpatialPartitioning class in the CI test  
  • Add PCH to Common containing the Commonly used Point types
  • Use Explicit instantiation to instantiate commonly used Point class in the CI test  
  • Add PCH to std library (to speed up CI test parsing of <array>, <random>...)

Troubleshooting notes

When testing the compile target linkage to the precompiled header with :

g++ -O2 -I . -I Ponca/precompiled/Fitting -I ./external/eigen -c tests/src/fit_cov.cpp -o fit_cov.o
ar rcs fit_cov.a fit_cov.o
nm fit_cov.a | c++filt | grep Basket
                 U vtable for Ponca::Basket<Ponca::PointPositionNormal<double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<double, 3>, Ponca::SmoothWeightKernel<double> >, Ponca::MeanPosition, Ponca::CovarianceFitBase>
0000000000000000 V vtable for Ponca::Basket<Ponca::PointPositionNormal<double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<double, 3>, Ponca::SmoothWeightKernel<double> >, Ponca::PrimitiveBase, Ponca::MeanPosition, CovarianceFitTwoPassesBase>
                 U vtable for Ponca::Basket<Ponca::PointPositionNormal<double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<double, 3>, Ponca::ConstantWeightKernel<double> >, Ponca::MeanPosition, Ponca::CovarianceFitBase>
0000000000000000 V vtable for Ponca::Basket<Ponca::PointPositionNormal<double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<double, 3>, Ponca::ConstantWeightKernel<double> >, Ponca::PrimitiveBase, Ponca::MeanPosition, CovarianceFitTwoPassesBase>
                 U vtable for Ponca::Basket<Ponca::PointPositionNormal<long double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<long double, 3>, Ponca::SmoothWeightKernel<long double> >, Ponca::MeanPosition, Ponca::CovarianceFitBase>
0000000000000000 V vtable for Ponca::Basket<Ponca::PointPositionNormal<long double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<long double, 3>, Ponca::SmoothWeightKernel<long double> >, Ponca::PrimitiveBase, Ponca::MeanPosition, CovarianceFitTwoPassesBase>
                 U vtable for Ponca::Basket<Ponca::PointPositionNormal<long double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<long double, 3>, Ponca::ConstantWeightKernel<long double> >, Ponca::MeanPosition, Ponca::CovarianceFitBase>
0000000000000000 V vtable for Ponca::Basket<Ponca::PointPositionNormal<long double, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<long double, 3>, Ponca::ConstantWeightKernel<long double> >, Ponca::PrimitiveBase, Ponca::MeanPosition, CovarianceFitTwoPassesBase>
                 U vtable for Ponca::Basket<Ponca::PointPositionNormal<float, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<float, 3>, Ponca::SmoothWeightKernel<float> >, Ponca::MeanPosition, Ponca::CovarianceFitBase>
0000000000000000 V vtable for Ponca::Basket<Ponca::PointPositionNormal<float, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<float, 3>, Ponca::SmoothWeightKernel<float> >, Ponca::PrimitiveBase, Ponca::MeanPosition, CovarianceFitTwoPassesBase>
                 U vtable for Ponca::Basket<Ponca::PointPositionNormal<float, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<float, 3>, Ponca::ConstantWeightKernel<float> >, Ponca::MeanPosition, Ponca::CovarianceFitBase>
0000000000000000 V vtable for Ponca::Basket<Ponca::PointPositionNormal<float, 3>, Ponca::DistWeightFunc<Ponca::PointPositionNormal<float, 3>, Ponca::ConstantWeightKernel<float> >, Ponca::PrimitiveBase, Ponca::MeanPosition, CovarianceFitTwoPassesBase>

We do find the U (undefined) symbol in the output, which validates that the compiler is using the extern templated class instead of recompiling it for the target.
However, the computation time increases compared to not using explicit instantiation, this might be because the inlined function are too costly to be preinstantiated by the compiler (further testing in progress).

@Me-k-01 Me-k-01 added the enhancement New feature or request label Dec 18, 2025
@Me-k-01 Me-k-01 self-assigned this Dec 18, 2025
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 18, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.03%. Comparing base (4cffe9d) to head (3d99e5a).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #241      +/-   ##
==========================================
- Coverage   94.07%   94.03%   -0.05%     
==========================================
  Files          83       83              
  Lines        3323     3300      -23     
  Branches      267      265       -2     
==========================================
- Hits         3126     3103      -23     
  Misses        196      196              
  Partials        1        1              
Files with missing lines Coverage Δ
tests/common/kdtree_utils.h 82.81% <ø> (ø)
tests/common/testUtils.h 100.00% <ø> (ø)
tests/src/barycenter.cpp 70.00% <ø> (ø)
tests/src/basket.cpp 98.97% <ø> (ø)
tests/src/binding.cpp 98.38% <ø> (ø)
tests/src/change_basis.cpp 97.36% <ø> (ø)
tests/src/cnc.cpp 95.29% <ø> (ø)
tests/src/curvature_plane.cpp 96.42% <ø> (ø)
tests/src/fit_cov.cpp 95.31% <ø> (ø)
tests/src/fit_line.cpp 96.55% <ø> (ø)
... and 15 more

... and 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch from 390c0e6 to a35af0e Compare January 9, 2026 13:11
@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch from 27c8481 to e5e780d Compare February 13, 2026 13:33
@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch 7 times, most recently from 652ce6e to dd27477 Compare March 16, 2026 14:27
@nmellado
Copy link
Copy Markdown
Contributor

  • Add precompiled Eigen target file

This is not relevant, as Eigen use templates to optimize mathematical operations you have in your code, so you cannot pre-compile it.

@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch 11 times, most recently from 5f8713a to 2c1b865 Compare March 20, 2026 13:31
@nmellado nmellado changed the title [cmake] Add a precompile header to the Fitting module [cmake] Optimize compilation performances Mar 20, 2026
@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch 3 times, most recently from 4871b8c to 97b5698 Compare March 24, 2026 08:28
@nmellado nmellado mentioned this pull request Mar 24, 2026
2 tasks
fauberva and others added 27 commits April 13, 2026 09:30
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
- Removal of extern instruction
- Macro name change
- Comment of incomplete fit type

Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
…//stackoverflow.com/questions/2351148/explicit-template-instantiation-when-is-it-used)

ETI Tells the compiler to use the extern `Basket` class instead of recompiling it for every compile targets.

Signed-off-by: fauberva <florian.auberval@irit.fr>
… test

Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Precompile the header before, not for each test

Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <florian.auberval@irit.fr>
- Only keep one header to precompile
- Add an option to generate precompiled header for each target

Signed-off-by: fauberva <florian.auberval@irit.fr>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <auberval.florian01@gmail.com>
Signed-off-by: fauberva <florian.auberval@irit.fr>
@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch from 7fd7dd2 to 828af24 Compare April 13, 2026 07:30
Signed-off-by: fauberva <florian.auberval@irit.fr>
@Me-k-01 Me-k-01 force-pushed the precompiled-headers branch from b668121 to f7f803a Compare April 13, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants