EditableMesh causes the Main/Render thread to freeze when setting certain attributes

Setting EditableMesh:SetNormal() can be extremely slow, especially as the number of vertices sharing the same normal id increases.


The problem seems to be because of DynamicGeometryManager :: transcodeVerticesAndCalculateBounds. In my case, it took 135ms to process when :SetNormal() was called on a normal id, where 1000 vertices are sharing the same normalId.

The problem is made even worse since the time complexity is O(n^2)


where the x-axis is time (seconds) and the y-axis is number of vertices sharing the same normal id that is being set.
This means that if you have 20,000 vertices sharing a normal id, it’ll crash the game since it takes too long to compute.

System Information:

Windows 10
Intel i5-9400F
NVidea GeForce GTX 1650
16GB RAM

Expected behavior

It should only be taking a few milliseconds.

1 Like

Thanks for the report, this is definitely something that needs to be optimized.

It seems that the likely culprit is automatic normal computation. For the normal in question, does setting its value manually improve the performance?

emesh:SetNormal(nid, emesh:GetNormal(nid))

2 Likes

Unfortunately not, it still takes the same amount of time.

1 Like

Okay, thanks for checking, and for the report. I’ll give it a look.

2 Likes

Hey there, just checking in - any updates?

Hi, I haven’t taken a look at it yet, it’s still on my backlog. Thanks for the reminder