Hi all,
I've been wrestling with long compile times in graph-tool while doing some
development work, and I noticed that template instantiations seem to be an
important factor. Even functions of modest compile time can be very slow if
they are multiplied by the product of several type alternatives, each of
which much be instantiated. For example, a single function in Python may
dispatch to N graph types x M degree map types x P weight map types, which
can mean hundreds of instantiations.
At the same time I noticed a pattern in the code where there is a set of
types (represented by a Boost.MPL typelist) that accompany a boost::any
argument. At dispatch time the "any" object is interrogated to find out
which of the types it stores, and the correct instantiation is called.
Dispatching this way requires a linear search through the typelist for each
argument.
It seems to me that replacing (MPL typelist + boost::any) with std::variant
would improve both of those factors with:
1. Constant time dispatch to the appropriate instantiation via std::visit
2. The ability to reduce compile time by reducing the N x M... type
product, depending on how well the argument use can be refactored.
I think the approach described in
http://jefftrull.github.io/c++/boost/python/2020/01/30/variants-in-boost-python.html
could
be applied here.
Would there be any interest in exploring this kind of refactoring? I think
there could be substantial benefits in compile time, as well as some
runtime improvement (depending on how often the Python/C++ boundary is
crossed).
Thanks,
Jeff
attachment.html (1.88 KB)