Skip to content

Commit d951b9d

Browse files
elbenomjcaisse-intel
authored andcommitted
⚡ Improve compilation benchmark
The change to use `gather_by` provides a good speedup; a few other things provide small speedups.
1 parent 19cadcf commit d951b9d

File tree

7 files changed

+39
-32
lines changed

7 files changed

+39
-32
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ include(cmake/string_catalog.cmake)
2424

2525
add_versioned_package("gh:boostorg/mp11#boost-1.83.0")
2626
fmt_recipe(10.2.1)
27-
add_versioned_package("gh:intel/cpp-std-extensions#646bdbe")
27+
add_versioned_package("gh:intel/cpp-std-extensions#2fc35c7")
2828
add_versioned_package("gh:intel/cpp-baremetal-concurrency#fef18ca")
2929
add_versioned_package("gh:intel/cpp-baremetal-senders-and-receivers#113eeff")
3030

include/cib/callback.hpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,14 @@ template <int NumFuncs = 0, typename... ArgTypes> struct callback {
4545
template <std::convertible_to<func_ptr_t>... Fs>
4646
// NOLINTNEXTLINE(cppcoreguidelines-missing-std-forward)
4747
[[nodiscard]] constexpr auto add(Fs &&...fs) const {
48-
return [&]<std::size_t... Is>(std::index_sequence<Is...>) {
49-
return callback<NumFuncs + sizeof...(Fs), ArgTypes...>{
50-
{funcs[Is]..., std::forward<Fs>(fs)...}};
51-
}(std::make_index_sequence<NumFuncs>{});
48+
callback<NumFuncs + sizeof...(Fs), ArgTypes...> cb;
49+
auto i = std::size_t{};
50+
while (i < NumFuncs) {
51+
cb.funcs[i] = funcs[i];
52+
++i;
53+
}
54+
((cb.funcs[i++] = std::forward<Fs>(fs)), ...);
55+
return cb;
5256
}
5357

5458
/**

include/cib/detail/config_details.hpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,33 @@ template <auto Value>
1313
constexpr static auto as_constant_v =
1414
std::integral_constant<std::remove_cvref_t<decltype(Value)>, Value>{};
1515

16-
template <auto... Args> struct args {
17-
constexpr static auto value = stdx::make_tuple(as_constant_v<Args>...);
18-
};
16+
template <auto... Args> struct args {};
17+
18+
template <typename...> struct config;
1919

20-
template <typename ConfigArgs, typename... ConfigTs>
21-
struct config : public detail::config_item {
20+
template <auto... ConfigArgs, typename... ConfigTs>
21+
struct config<args<ConfigArgs...>, ConfigTs...> : public detail::config_item {
2222
stdx::tuple<ConfigTs...> configs_tuple;
2323

24-
CONSTEVAL explicit config(ConfigArgs, ConfigTs const &...configs)
24+
CONSTEVAL explicit config(args<ConfigArgs...>, ConfigTs const &...configs)
2525
: configs_tuple{configs...} {}
2626

2727
template <typename... Args>
2828
[[nodiscard]] constexpr auto extends_tuple(Args const &...args) const {
29-
return ConfigArgs::value.apply([&](auto const &...config_args) {
30-
return configs_tuple.apply([&](auto const &...configs_pack) {
31-
return stdx::tuple_cat(
32-
configs_pack.extends_tuple(args..., config_args...)...);
33-
});
29+
return configs_tuple.apply([&](auto const &...configs_pack) {
30+
return stdx::tuple_cat(configs_pack.extends_tuple(
31+
args..., as_constant_v<ConfigArgs>...)...);
3432
});
3533
}
3634

3735
template <typename... Args>
3836
[[nodiscard]] constexpr auto exports_tuple(Args const &...args) const {
39-
return ConfigArgs::value.apply([&](auto const &...config_args) {
40-
return configs_tuple.apply([&](auto const &...configs_pack) {
41-
return stdx::tuple_cat(
42-
configs_pack.exports_tuple(args..., config_args...)...);
43-
});
37+
return configs_tuple.apply([&](auto const &...configs_pack) {
38+
return stdx::tuple_cat(configs_pack.exports_tuple(
39+
args..., as_constant_v<ConfigArgs>...)...);
4440
});
4541
}
4642
};
43+
44+
template <typename... Ts> config(Ts...) -> config<Ts...>;
4745
} // namespace cib::detail

include/cib/detail/config_item.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
namespace cib::detail {
66
struct config_item {
77
template <typename... Args>
8-
[[nodiscard]] constexpr auto extends_tuple(Args const &...) const {
9-
return stdx::make_tuple();
8+
[[nodiscard]] constexpr auto
9+
extends_tuple(Args const &...) const -> stdx::tuple<> {
10+
return {};
1011
}
1112

1213
template <typename... InitArgs>
13-
[[nodiscard]] constexpr auto exports_tuple(InitArgs const &...) const {
14-
return stdx::make_tuple();
14+
[[nodiscard]] constexpr auto
15+
exports_tuple(InitArgs const &...) const -> stdx::tuple<> {
16+
return {};
1517
}
1618
};
1719
} // namespace cib::detail

include/cib/detail/exports.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ template <typename ServiceT, typename BuilderT> struct service_entry {
1313

1414
template <typename... Services> struct exports : public detail::config_item {
1515
template <typename... InitArgs>
16-
[[nodiscard]] constexpr auto extends_tuple(InitArgs const &...) const {
17-
return stdx::make_tuple(extend<Services>{}...);
16+
[[nodiscard]] constexpr auto extends_tuple(InitArgs const &...) const
17+
-> stdx::tuple<extend<Services>...> {
18+
return {extend<Services>{}...};
1819
}
1920

2021
template <typename... InitArgs>
21-
[[nodiscard]] constexpr auto exports_tuple(InitArgs const &...) const {
22-
return stdx::make_tuple(Services{}...);
22+
[[nodiscard]] constexpr auto
23+
exports_tuple(InitArgs const &...) const -> stdx::tuple<Services...> {
24+
return {};
2325
}
2426
};
2527
} // namespace cib::detail

include/cib/detail/extend.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@ struct extend : public config_item {
1616
CONSTEVAL explicit extend(Args const &...args) : args_tuple{args...} {}
1717

1818
template <typename... InitArgs>
19-
[[nodiscard]] constexpr auto extends_tuple(InitArgs const &...) const {
20-
return stdx::make_tuple(*this);
19+
[[nodiscard]] constexpr auto
20+
extends_tuple(InitArgs const &...) const -> stdx::tuple<extend> {
21+
return {*this};
2122
}
2223
};
2324
} // namespace cib::detail

include/cib/detail/nexus_details.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ constexpr static auto initialized_builders = transform<extract_service_tag>(
3636
return detail::service_entry<service, decltype(built_service)>{
3737
built_service};
3838
},
39-
chunk_by<get_service>(sort<get_service>(Config::config.extends_tuple())));
39+
stdx::gather_by<get_service>(Config::config.extends_tuple()));
4040

4141
template <typename Config, typename Tag> struct initialized {
4242
constexpr static auto value =

0 commit comments

Comments
 (0)