Archived
use extern template in generated c++ files
hi.
the files generated by slice2cpp
contain a lot of templates.
template instantiations slow down compilation.
a way to circumvent this problem is to use a explicit instantiation declaration
for the template instance in the header and add the explicit instantiation declaration
to the cpp (see here for more information).
i think it would be nice if slice2cpp
would use this feature (this can speed up the compilation of large code-bases).
since explicit instantiation declarations
are a c++11 feature, this probably should be enabled via a flag.
will you add such a flag to slice2cpp
in future?
best regards.
raphael
Comments
-
Hi Raphael,
We're always looking for ways to improve Ice, so thanks for the suggestion!
slice2cpp
does indeed rely on template instantiations, even more so with the new C++11 mapping.Did you update some of the generated .h and .cpp for your Slice files with explicit template instantiations to verify it this does indeed reduce your compilation time? Which Ice version and C++ compiler are you working with?
Explicit template instantiations have some downsides as well:
- our template have quite a bit of inline code--explicit instantiations would not / should not help for those
- explicitly instantiating every template class and member function in a generated .h, even those you never use, could lead to code bloat, which in turn can create other problems, see for example: https://forums.zeroc.com/discussion/comment/46600
- the interaction with "dll export" (and similar non-hidden symbols with gcc/clang) can be tricky
We actually used some explicit template instantiations in the generated code with Ice 3.6 (Windows only), but removed it for Ice 3.7 to reduce code size: https://github.com/zeroc-ice/ice/commit/c474b08073c63f6b1fcffe33a5d8172702c4d1f9Best regards,
Bernard0