adiar icon indicating copy to clipboard operation
adiar copied to clipboard

Improve performance of copying and referencing `exec_policy`

Open SSoelvsten opened this issue 1 year ago • 0 comments

In #546 , we cleaned up the interface to use an exec_policy object to be passed around, instead of reading (thread unsafely) from a set of global enum values. Based on the preliminary experiments in #548 , this change does not seem to have negatively affected the performance of Adiar (the 9-queens slowdown could just as much be noise in the experiments). Yet, we have introduced the need to construct, reference, and copy this object, so we should make sure it is as cheap as possible.

Currently, sizeof(adiar::exec_policy) evaluates to 12. That is, each enum is encoded as a 32 bit number. This will only get worse, as we add more settings into it. It is much cheaper to just move a single 64 bit number around (it is a single number in a register) than storing the struct on the stack. Doing so will also improve alignment.

  • [ ] Make all but the copy and move constructors constexpr. This ensures all overloads that create a new default policy with exec_policy() evaluate at compile-time (and hence are faster).
  • [ ] Use bit-manipulation to store all the enum values within a single 64 bit number. Or at least decrease all enums to unsigned char.

SSoelvsten avatar Oct 01 '23 18:10 SSoelvsten