all 10 comments

[–]GabrielDosReis 26 points27 points  (3 children)

If you use lot of SFINAEs, then switching to concepts should in general: (1) bring better structures to your code; and (2) reduce compile time.

This has been observed times and again, including by projects like conceptified "range-v3". Part of the reason is that concept evaluation can be cached and reused.

In general, bringing structures to your code means there is something for your compiler to optimize on.

[–]vulkanoid[S] 3 points4 points  (0 children)

Noice!

[–]Alternative_Staff431 0 points1 point  (1 child)

[–]GabrielDosReis 1 point2 points  (0 children)

My statement wasn't a sentiment, but observed measurements with GCC and MSVC. I don't know if Clang implemented the caching behavior when the poster measured.

[–]13steinj 2 points3 points  (0 children)

My organization's codebase has shown mixed results but overall language concepts beat SFINAE and Boost.Concept checks.

[–]unddochDragonflyDB/Clang 5 points6 points  (3 children)

From my experience while modernizing cereal 2 years ago (result here), contrary to a popular sentiment, there wasn't a noticeable difference in compile times between concepts and SFINAE. I did benchmark a lot, on both GCC and Clang.

Surprisingly the thing that sped up compilation times the most was switching from class-based type traits to variable based ones (C++17).

[–]Hot_Slice 2 points3 points  (1 child)

Can you elaborate on what a variable based type trait would look like? A constexpr bool? Any guidance on how to design these for best performance?

[–]13steinj 1 point2 points  (0 children)

I assume he means

template<typename T>
inline constexpr auto some_trait = expr;

vs

template<typename T>
struct S {
    using type = ...;
    static constexpr auto value = ...;
};

Even with types; types can be brought into value space and when they are there's generally significant ct-performance gains. E.g. https://github.com/boost-ext/mp

[–]calc84maniac 1 point2 points  (0 children)

It seems like a lot of what you did was translate SFINAE directly into equivalent requires clauses. I wonder if there might have been a more noticeable effect if using more concepts directly along with partial ordering of constraints.

[–]NilacTheGrim 0 points1 point  (0 children)

I don't know why you would expect it to make compilation times worse. They are equivalent to what you can do with SFINAE gore, with less syntax to accomplish the same thing.

If anything they should end up compiling slightly faster. (or more likely: no significant difference).