From 9088a1f4764f371f7f22384e7d7e2c8971d5c9f0 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Mon, 12 Sep 2022 11:35:33 -0500 Subject: Geometry: Avoid unnecessary initialization when resizing data arrays When resizing mesh and curves attribute storage, avoid initializing the new memory for basic types. Also, avoid skipping "no free" layers; all layers should be reallocated to the new size since they may be accessed. The semantics introduced in 25237d2625078c6d1 are essential for this change, because otherwise we don't have a way to construct non-trivial types in the new memory. In a basic test of the extrude node, I observed a performance improvement of about 30%, from 55ms to 42ms. Differential Revision: https://developer.blender.org/D15818 --- .../blender/geometry/intern/add_curves_on_mesh.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source/blender/geometry') diff --git a/source/blender/geometry/intern/add_curves_on_mesh.cc b/source/blender/geometry/intern/add_curves_on_mesh.cc index e06ee55afa0..bb5e2a0a28a 100644 --- a/source/blender/geometry/intern/add_curves_on_mesh.cc +++ b/source/blender/geometry/intern/add_curves_on_mesh.cc @@ -372,6 +372,28 @@ AddCurvesOnMeshOutputs add_curves_on_mesh(CurvesGeometry &curves, curves.fill_curve_types(new_curves_range, CURVE_TYPE_CATMULL_ROM); + /* Explicitly set all other attributes besides those processed above to default values. */ + bke::MutableAttributeAccessor attributes = curves.attributes_for_write(); + Set attributes_to_skip{{"position", + "curve_type", + "surface_uv_coordinate", + ".selection_point_float", + ".selection_curve_float"}}; + attributes.for_all( + [&](const bke::AttributeIDRef &id, const bke::AttributeMetaData /*meta_data*/) { + if (id.is_named() && attributes_to_skip.contains(id.name())) { + return true; + } + bke::GSpanAttributeWriter attribute = attributes.lookup_for_write_span(id); + const int new_elements_num = attribute.domain == ATTR_DOMAIN_POINT ? new_points_num : + new_curves_num; + const CPPType &type = attribute.span.type(); + GMutableSpan new_data = attribute.span.take_back(new_elements_num); + type.fill_assign_n(type.default_value(), new_data.data(), new_data.size()); + attribute.finish(); + return true; + }); + return outputs; } -- cgit v1.2.3