tskit icon indicating copy to clipboard operation
tskit copied to clipboard

use restrict pointers in tsk_bit_array_* methods

Open jeromekelleher opened this issue 2 years ago • 2 comments

The bit_array methods currently have pointer chasing like self->data within loops, which might reduce performance. It's worth declaring restrict pointers for these to help the compiler out.

void
tsk_bit_array_add(tsk_bit_array_t *self, const tsk_bit_array_t *other)
{
    tsk_size_t i;
   const tsk_size_t size = self->size;
   tsk_bit_array_value_t * restrict self_data = self->data;
   const tsk_bit_array_value_t * restrict other_data = other->data;

    for (i = 0; i < size; i++) {
        self_data[i] |= other_data[i];
    }
}

I've made the size const as well here because the compiler might not (it probably would, but I'm not sure) know that this value is constant, and might decide to load the value from memory. Since this is perf sensitive, it's good to help the compiler out as much as possible.

jeromekelleher avatar Aug 30 '23 08:08 jeromekelleher

Closing for inactivity and labelling "future", please re-open if you plan to work on this.

benjeffery avatar Jun 15 '25 23:06 benjeffery

Reopening this as it's ongoing work

jeromekelleher avatar Jun 16 '25 08:06 jeromekelleher