Functions: parallelize materializing arrays after field evaluation

This improves performance e.g. when creating an integer attribute
based on an index field. For 4 million vertices, I measured a speedup
from 3.5 ms to 1.2 ms.
This commit is contained in:
Jacques Lucke 2022-04-07 09:48:07 +02:00
parent fd5e5dac89
commit 2aff04917f
1 changed files with 11 additions and 6 deletions

View File

@ -468,16 +468,21 @@ Vector<GVArray> evaluate_fields(ResourceScope &scope,
/* Still have to copy over the data in the destination provided by the caller. */
if (dst_varray.is_span()) {
/* Materialize into a span. */
computed_varray.materialize_to_uninitialized(mask, dst_varray.get_internal_span().data());
threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange range) {
computed_varray.materialize_to_uninitialized(mask.slice(range),
dst_varray.get_internal_span().data());
});
}
else {
/* Slower materialize into a different structure. */
const CPPType &type = computed_varray.type();
BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
for (const int i : mask) {
computed_varray.get_to_uninitialized(i, buffer);
dst_varray.set_by_relocate(i, buffer);
}
threading::parallel_for(mask.index_range(), 2048, [&](const IndexRange range) {
BUFFER_FOR_CPP_TYPE_VALUE(type, buffer);
for (const int i : mask.slice(range)) {
computed_varray.get_to_uninitialized(i, buffer);
dst_varray.set_by_relocate(i, buffer);
}
});
}
r_varrays[out_index] = dst_varray;
}