Page MenuHome

Subdiv: Avoid quadratic runtime for loose edges
ClosedPublic

Authored by Hans Goudey (HooglyBoogly) on Sep 9 2022, 6:56 AM.
Tags
None
Subscribers
None
Tokens
"Love" token, awarded by OcularEvolution."Love" token, awarded by hitrpr."Love" token, awarded by Raimund58."Party Time" token, awarded by pablovazquez.

Details

Summary

Currently, when subdividing every single vertex on every loose edge,
Blender iterates over all other edges to find neighbors. This has
quadratic runtime and can be very slow. Instead, first create a
map of edges connected to each vertex.

With about 10000 edges, the performance goes from very slow to very
smooth in my tests. Because of the nature of quadratic runtime, the
improvement will depend massively on the number of elements.

The only downside to this is that the map will still be built when
there are only a couple loose edges, but that case is probably not
so common.

Diff Detail

Repository
rB Blender

Event Timeline

Hans Goudey (HooglyBoogly) requested review of this revision.Sep 9 2022, 6:56 AM
Hans Goudey (HooglyBoogly) created this revision.

That's great!

source/blender/blenkernel/intern/subdiv_mesh.cc
69

Since it is C++ and is new code, would it make sense to use Vector instead of the bare pointer?

This revision is now accepted and ready to land.Sep 9 2022, 9:51 AM
source/blender/blenkernel/intern/subdiv_mesh.cc
69

Agreed with the sentiment! This is allocated by BKE_mesh_vert_edge_map_create though, which still is just a C API.
I'd like to change it a bit more soon to make it friendlier using more C++ features

source/blender/blenkernel/intern/subdiv_mesh.cc
69

Ah, indeed! More proper C++ would be welcome :)