RainerKuemmerle / g2o

g2o: A General Framework for Graph Optimization
3.1k stars 1.11k forks source link

VCE2010 Win7 x64 - Slow compilation time #24

Closed nbriox closed 10 years ago

nbriox commented 11 years ago

Hi all. I successfully compiled the g2o library (MSVCE 2010 on windows 7 64 bit) and I'm using it in my SLAM framework as back-end optimization step. I noticed that the time required for compiling the SLAM framework considerably increased since when I added the g2o library. In particular, the compilation itself goes really slow (more than 2 minute) and requires a huge amount of memory (more than 1GB). Linking instead is pretty fast. Once I remove the g2o from the project, everything compiles in reasonable time. Do you have any hint to explain this behavior? It seems to me that the compiler waste a lot of time scanning all the header file hierarchy.. Can be?

PS. I'm not rebuilding the whole g2o library in my project

Thank you

RainerKuemmerle commented 11 years ago

I'm not a regular user of Windows and Visual Studio but I guess you are right. Much of our code is based on templates, in particular the solvers are templates.

For the algorithms I typically just obtain a pointer via the factory to avoid including all the templates in my code. For example:

#include "g2o/core/optimization_algorithm_property.h"
#include "g2o/core/optimization_algorithm_factory.h"
#include "g2o/core/sparse_optimizer.h"
#include "g2o/core/hyper_graph_action.h"

// force linking to the g2o csparse solvers
G2O_USE_OPTIMIZATION_LIBRARY(csparse);

// ....

  _optimizer = new g2o::SparseOptimizer;
  g2o::OptimizationAlgorithmFactory* solverFactory = g2o::OptimizationAlgorithmFactory::instance();
  g2o::OptimizationAlgorithmProperty properties;
  g2o::OptimizationAlgorithm* algorithm = solverFactory->construct("gn_var", properties);
  //g2o::OptimizationAlgorithm* algorithm = solverFactory->construct("lm_var", properties);
  _optimizer->setAlgorithm(algorithm);