Don't assume compiler memoization #3

Open
opened 4 years ago by tcsullivan · 1 comments
tcsullivan commented 4 years ago (Migrated from github.com)

See here.

Code like below (taken from the link) calls build_node_list three times, and there's a chance this causes the compile to recompute the list with every call. There is significant compilation overhead in this project, so I wouldn't be surprised if this is the case.

auto list = build_node_list();
auto tree = std::span(new node[tree_count()] {}, tree_count());

Need to minimize recomputation, or find ways to avoid it altogether.

See [here](https://www.reddit.com/r/cpp/comments/kn1wpe/compiletime_string_compression_using_huffman/ghjm993/). Code like below (taken from the link) calls `build_node_list` three times, and there's a chance this causes the compile to recompute the list with every call. There is significant compilation overhead in this project, so I wouldn't be surprised if this is the case. ```cpp auto list = build_node_list(); auto tree = std::span(new node[tree_count()] {}, tree_count()); ``` Need to minimize recomputation, or find ways to avoid it altogether.
tcsullivan commented 4 years ago (Migrated from github.com)

Forced memoization for the node list, tree count, and compressed size. The JSON example now compiles ~30% faster on my desktop. The sizes are stored in constexpr static variables, while the node list became a constexpr static object with a consteval constructor.

My attempt at memoization for the node tree failed terribly (>100% increase in compile time). I did it in the same way I did for the node list, maybe I messed something up; I'll continue to look into it.

Forced memoization for the node list, tree count, and compressed size. The JSON example now compiles ~30% faster on my desktop. The sizes are stored in `constexpr static` variables, while the node list became a `constexpr static` object with a `consteval` constructor. My attempt at memoization for the node tree failed terribly (>100% increase in compile time). I did it in the same way I did for the node list, maybe I messed something up; I'll continue to look into it.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: clyne/consteval-huffman#3
Loading…
There is no content yet.