Skip to content

Optimize repeat buffers in for_each_element #584

Description

@dsharlet

Due to aliasing and in-place optimizations, it's often the case that for_each_element will be called with the same buffer passed more than once. We can avoid the loop logic for the extra buffer in that case.

In other words, something like:

for_each_element(x, [](int* x_i, const int* y_i) { *x_i = f(*y_i); }, y)

Where y happens to be equal to x, could be rewritten:

for_each_element(x, [](int* x_i) { *x_i = f(*x_i); })

This would save a little overhead in make_for_each_loops and for_each_element's implementation.

However, doing this safely and efficiently enough to be worth doing is tricky.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions