I often build definitions where I’m remapping geometry between two meshes of equivalent topology. I’ll often be passing 100k points through Mesh Closest Point and Mesh Eval in native Grasshopper. I’ve been looking at ways to speed this process up. I thought that scripting these functions through RhinoCommon in Python or C#, especially once multi-threaded would have speeded things up. Though I’m finding that stock Grasshopper components perform faster.
Here are my results for remapping 10k points on a six core CPU:
- Stock GH components: 75ms (adding the times for all components, none are multithreaded)
- Python single thread: 360ms
- Python multi thread through ghpythonlib.parallel: 150ms
- C# single thread: 265ms
- C# multi-thread through Parallel.For(): 130ms
While multi-threading is providing a nice speed boost, I’m really surprised GH components still compute faster for this test scenario.
I was hoping to hear thoughts from other users:
- Any thoughts on how to improve the compute speed for this operation?
- Is something very wrong with the way I wrote my scripts that is slowing them?
- Is there a way to profile a script to see where the time is spent?
- Would a compiled Visual Studio component perform significantly faster?
- Do you usually see a performance increase by replacing components with scripts?
I’ve attached my test file with the scripts attached. The output isn’t especially useful as I isolated a portion I repeat in a lot of scripts.