Why does GetConnectedVertices take so much longer for a mesh with color

I am hoping someone can explain why using GetConnectedVertices takes 53x! longer running the exact same mesh, but with vertex colors added?? This is a super simplified example of the issue I am having.

This further confuses me:

Press F5 a few times, does the measured time change?

The first time a script component runs it is delayed by the time it takes to compile the code. Although 5 seconds is beyond ridiculous, compilation tends to take less than half a second usually.

Hi David, thanks for taking sometime to help me understand this. It has been plaguing me for a while with some components I am working on. It is not simply the compile time unfortunately. I reconnect the wires a couple times to get a sense of the average compute times after the script components compile.

I was originally under the impression that this was resulting from adding vertex color information to the mesh, but it seems pretty clear that is not the cause now:

In the process of saving this as a new file to include for you to look at, when reopened it computes both slowly now:

But this is out of a file that has been saved, closed and reopened many times without changing the behavior.

Is there some way for me to compare the details of the data within the two meshes being passed so I can understand why its efficient with one and not the other? Could this have to do with how the mesh is being stored?

I just noticed you’re using LINQ. Would be interesting to know how that affects the performance. I remember reading about LINQ being ridiculously slow and weird, but that was in the early days, it was supposed to have been vastly improved since.

I figured it out! Very interested to hear your thoughts on this David. So it seems that when the mesh is put through a contour component, it does something that allows the GetConnectedVertices to run much more efficiently.

if GetConnectedVertices is called before the mesh is processed by the contour component, it is slow.
(I am assuming the components are run in the order of creation because that is the behavior I am seeing)
If the wire with the C# component created before is reconnected it runs fast.

If a contour component is connected to the freshly constructed mesh, and the C# component is reconnected it also runs fast.

here is the file if you want to have a look:
getconnectedvertices_slowMesh_contour.gh (16.7 KB)

1 Like

So we’re left with the conclusion that the time is taken up computing the topology of the mesh. And for some reason which I will try to find the topology isn’t cached in the script in some circumstances and therefore has to be computed over and over again… Thanks for figuring this out.