perf: avoid copying rvalue meshes when adding model volumes - #12116
perf: avoid copying rvalue meshes when adding model volumes#12116VailElla wants to merge 1 commit into
Conversation
6048533 to
98485fd
Compare
Haidiye00
left a comment
There was a problem hiding this comment.
Hi, under what bug is this? Does it need to be fixed this way? Can you tell me what this bug is?
|
Hi, thank you for taking a look. This PR is not intended to fix a user-visible functional bug. It addresses an unnecessary deep copy on an existing rvalue code path. ModelObject::add_volume(TriangleMesh&&) already forwards the mesh as an rvalue to ModelVolume. Before this change, ModelVolume did not have a matching TriangleMesh&& constructor, so the call selected the const TriangleMesh& constructor. That constructor creates a new TriangleMesh(mesh), copying the vertex and index buffers even though the rvalue no longer needs to retain its original storage. The added constructor keeps the existing std::shared_ptr storage model, but moves the mesh into that shared object. This preserves immutable mesh storage, leaves the lvalue overload and other ownership behavior unchanged, and keeps the existing convex-hull initialization. The regression test checks that the vertex and index buffer addresses are transferred rather than copied, and that the convex hull is still initialized. On high-poly models, this path can involve millions of vertices and indices, so the goal is to reduce loading memory traffic and peak memory without changing geometry or slicing behavior. I chose this implementation to keep the change local to ModelVolume and avoid changing the existing ModelObject::add_volume API. If you prefer this to be tracked under a performance issue, or would like a dedicated benchmark added to the PR, I can add that and adjust the patch accordingly. |
Summary
TriangleMeshwhenModelObject::add_volumereceives an rvalueValidation
cmake --build build/arm64 --target libslic3r --parallel 8fff_print_testsregression:ModelObject moves rvalue mesh storage into a volumegit diff --checkThe full
fff_print_teststarget is currently blocked by pre-existing test sources that use an olderGCodeWriterAPI (set_extruder,lift, andretract_lift); those failures are unrelated to this change.