Brep Edges equivalent in C#

Hello everyone!

I am trying to recreate the Brep Edges component in a c# component. There are probably multiple ways to do this. So far I’ve tried:

  • Brep.Edges
  • Brep.Curves3D
  • Brep.DuplicateEdgeCurves()
  • Brep.Loops

Via all of these I get the desired edges, however, the standard Brep Edges component in Grasshopper is about 3 times as fast as all of these options. How is that possible? Is there another fast (and maybe obvious) way I am missing to determine the edges of a brep?

Of course it is not a big problem to insert the edges of breps into the c# for further use, however I’d like to incorporate everything into one c# component. I’m inserting multiple thousand complex Breps, and therefore like to optimize my code :slight_smile:

Thanks in advance!

How are you measuring the performance? Are you sure you’re not pitting a Debug build against a Release build? If your code is inside a C# script component, it will always run slower because of the overhead of duplicating the Brep whenever it goes in.

Are you outputting the curves as RhinoCommon Curve or wrapping in a GH_Curve before outputting? I have found that can make a sizeable difference for the C# component performance, particularly if the computation is relatively light but you are generating a lot of output data. I expect David knows why this is, guess it has to do with some type checking to work out what sort of goo to wrap each geometry with.

Measuring the performance is done, quite prehistorically, by comparing the profiler widget speeds. This also means that I’m using the C# script component inside grasshopper, so no debug build/release build.

Thanks for explaining that the script component always runs slower due to the overhead. I’ll try to make a component in Visual Studio and see if that will run faster. It will be a good exercise to start scripting in Visual Studio! :smiley:

Thanks for your answers!

Well … even with no // implemented (is a public build) I can’t see any noticable perf diff. See attached

Brep_EdgesAndConn.3dm (4.4 MB)
Brep_EdgesAndConn.gh (119.5 KB)