C# component speed - Grasshopper2024-03-29T02:06:21Zhttps://www.grasshopper3d.com/forum/topics/c-component-speed?commentId=2985220%3AComment%3A1849820&feed=yes&xn_auth=nonow I started to modify code…tag:www.grasshopper3d.com,2017-11-15:2985220:Comment:18539142017-11-15T18:42:11.765ZShimpei Kojimahttps://www.grasshopper3d.com/profile/sinpeikojima
now I started to modify code using stopwatch class.<br />
<br />
Thank you for letting me know stopwatch class.
now I started to modify code using stopwatch class.<br />
<br />
Thank you for letting me know stopwatch class. Yeah Anders is right. Step 1…tag:www.grasshopper3d.com,2017-11-12:2985220:Comment:18517412017-11-12T17:42:01.399ZDavid Ruttenhttps://www.grasshopper3d.com/profile/DavidRutten
<p>Yeah Anders is right. Step 1 is <em>always</em> profiling. There's no point optimizing code until you know where the bottlenecks are. The Stopwatch class in System.Diagnostics is the best way to measure elapsed time, do <em>not</em> rely on DateTime.Now or DateTime.UtcNow, they have low accuracy.</p>
<p></p>
<p>Referencing assemblies shouldn't matter for performance. Choosing the right collection types can make a huge difference. Array vs. List vs. Stack vs. Dictionary vs. SortedList vs.…</p>
<p>Yeah Anders is right. Step 1 is <em>always</em> profiling. There's no point optimizing code until you know where the bottlenecks are. The Stopwatch class in System.Diagnostics is the best way to measure elapsed time, do <em>not</em> rely on DateTime.Now or DateTime.UtcNow, they have low accuracy.</p>
<p></p>
<p>Referencing assemblies shouldn't matter for performance. Choosing the right collection types can make a huge difference. Array vs. List vs. Stack vs. Dictionary vs. SortedList vs. HashSet vs. DataTree, .... you need to understand what operations you need most often and then decide which collection is best for you.</p>
<p></p>
<p>The C# component is standard .NET, however all code is compiled using DEBUG mode. This helps with finding problems, but sometimes you will get much better performance when you build RELEASE mode (especially with lots of Array interactions or GetPixel/SetPixel stuff).</p>
<p></p>
<p>But, start by profiling your code.</p> For instance, have a look at…tag:www.grasshopper3d.com,2017-11-11:2985220:Comment:18508952017-11-11T10:42:28.887ZAnders Holden Deleuranhttps://www.grasshopper3d.com/profile/AndersHoldenDeleuran
<p>For instance, have a look at how Dan has written the <a href="https://github.com/Dan-Piker/K2Goals" rel="nofollow" target="_blank">Kangaroo2 goals</a>: they for the most part only implement .NET (i.e. <span class="pl-k">using</span> <span class="pl-en">System.Foo) and the RhinoCommon geometry (i.e. <span class="pl-k">using</span> <span class="pl-en">Rhino.Geometry) namespaces. Using standard C# to structure the PPos, Move, and Weighting arrays, and not getting the Grasshopper namespace…</span></span></p>
<p>For instance, have a look at how Dan has written the <a rel="nofollow" href="https://github.com/Dan-Piker/K2Goals" target="_blank">Kangaroo2 goals</a>: they for the most part only implement .NET (i.e. <span class="pl-k">using</span> <span class="pl-en">System.Foo) and the RhinoCommon geometry (i.e. <span class="pl-k">using</span> <span class="pl-en">Rhino.Geometry) namespaces. Using standard C# to structure the PPos, Move, and Weighting arrays, and not getting the Grasshopper namespace involved at all here. The Kangaroo2 solver does though, since it does things that depend on it (updating the component over time, structuring goal data output into DataTrees etc.).</span></span></p> Well ... I would suggest to p…tag:www.grasshopper3d.com,2017-11-11:2985220:Comment:18508812017-11-11T07:11:23.476Zpeter fotiadishttps://www.grasshopper3d.com/profile/peterfotiadis
<p>Well ... I would suggest to post a portion (some Methods, that is) of your code (VS "many" elements) and we'll exploit ways to skip DataTrees (<span style="text-decoration: underline;"><strong>if</strong></span> "portability" is a goal) or // ways to do it.</p>
<p>Keep in mind that there's no magic red button that if pressed delivers wrap speed - // without some/proper scheduling is kinda a man without a Ducati.</p>
<p>On the other hand ... in real-life ... <strong>there's verticals already…</strong></p>
<p>Well ... I would suggest to post a portion (some Methods, that is) of your code (VS "many" elements) and we'll exploit ways to skip DataTrees (<span style="text-decoration: underline;"><strong>if</strong></span> "portability" is a goal) or // ways to do it.</p>
<p>Keep in mind that there's no magic red button that if pressed delivers wrap speed - // without some/proper scheduling is kinda a man without a Ducati.</p>
<p>On the other hand ... in real-life ... <strong>there's verticals already working fine</strong> within a given established AEC platform (Rhino/GH are <span style="text-decoration: underline;"><strong>NOT</strong></span> the things to use). Me? I'm working with Bentley Systems stuff (AECOSim + Generative Components + you name it).</p>
<p>There''s a clear and present danger to reinvent the wheel here.</p> Dear peter,
Thank you for rep…tag:www.grasshopper3d.com,2017-11-11:2985220:Comment:18509542017-11-11T00:50:57.057ZShimpei Kojimahttps://www.grasshopper3d.com/profile/sinpeikojima
<p>Dear peter,</p>
<p>Thank you for replying me.</p>
<p></p>
<p>I didn't know It depends on that what Rhino focused on...</p>
<p></p>
<p> I want to make component like 'Karamba' but I'm not sure when it will be done...</p>
<p>Dear peter,</p>
<p>Thank you for replying me.</p>
<p></p>
<p>I didn't know It depends on that what Rhino focused on...</p>
<p></p>
<p> I want to make component like 'Karamba' but I'm not sure when it will be done...</p> Dear Petras,
Thank you for re…tag:www.grasshopper3d.com,2017-11-11:2985220:Comment:18506992017-11-11T00:40:46.589ZShimpei Kojimahttps://www.grasshopper3d.com/profile/sinpeikojima
<p>Dear Petras,</p>
<p>Thank you for replying me.</p>
<p></p>
<p>In the future, I will analysis large scale building (many elements included, maybe over thousands)</p>
<p></p>
<p>I think I have to learn Multi-threading but it looks very diffcult and I worry about it will work in GH C#....</p>
<p>Dear Petras,</p>
<p>Thank you for replying me.</p>
<p></p>
<p>In the future, I will analysis large scale building (many elements included, maybe over thousands)</p>
<p></p>
<p>I think I have to learn Multi-threading but it looks very diffcult and I worry about it will work in GH C#....</p> Dear Anders,
Thank you for re…tag:www.grasshopper3d.com,2017-11-11:2985220:Comment:18506952017-11-11T00:36:01.343ZShimpei Kojimahttps://www.grasshopper3d.com/profile/sinpeikojima
<p>Dear Anders,</p>
<p>Thank you for replying me.</p>
<p></p>
<p>As you said, maybe I should use native .NET and RhinoCommon....</p>
<p></p>
<p>Can you tell me where <span>"Kangaroo2 follows this principle to a large extent for example" is said ?</span></p>
<p></p>
<p><span>Best,</span></p>
<p><span>Shimpei</span></p>
<p>Dear Anders,</p>
<p>Thank you for replying me.</p>
<p></p>
<p>As you said, maybe I should use native .NET and RhinoCommon....</p>
<p></p>
<p>Can you tell me where <span>"Kangaroo2 follows this principle to a large extent for example" is said ?</span></p>
<p></p>
<p><span>Best,</span></p>
<p><span>Shimpei</span></p> Impossible to suggest (or "su…tag:www.grasshopper3d.com,2017-11-09:2985220:Comment:18497862017-11-09T17:52:28.963Zpeter fotiadishttps://www.grasshopper3d.com/profile/peterfotiadis
<p>Impossible to suggest (or "suggest") anything without some piece of "representative" code. Have in mind as well that Rhino is a surface modeler meaning that pretty much any "solid" related Method is considerably slower than "some equivalent" in solid modeling aps.</p>
<p>But other than that you can entirely skip DataTrees with a variety of ways especially if you have plans to write some code that is as GH neutral as possible (that way you restrict changes by focusing to RhinoCommon classes…</p>
<p>Impossible to suggest (or "suggest") anything without some piece of "representative" code. Have in mind as well that Rhino is a surface modeler meaning that pretty much any "solid" related Method is considerably slower than "some equivalent" in solid modeling aps.</p>
<p>But other than that you can entirely skip DataTrees with a variety of ways especially if you have plans to write some code that is as GH neutral as possible (that way you restrict changes by focusing to RhinoCommon classes - in order, for example, to port your code to other holistic parametric AEC platforms like AECOSim + Generative Components + structural verticals [my case] and/or MCAD apps etc etc etc)</p> Normally you have one .dll /…tag:www.grasshopper3d.com,2017-11-09:2985220:Comment:18496812017-11-09T15:58:51.981ZPetras Vestartashttps://www.grasshopper3d.com/profile/PetrasVestartas
<p>Normally you have one .dll / Visual Studio project with core functionality and component should work only as interface for calling functions. It is also easier to track what you did some time ago.</p>
<p></p>
<p>But in general if you are not outputting 10 of thousands elements from one component like with Kanaroo2 Goals , then it is your solution and solver which should be optimized. Multi-threading is additional option, but you have to know how to do it correctly.</p>
<p></p>
<p></p>
<p>Normally you have one .dll / Visual Studio project with core functionality and component should work only as interface for calling functions. It is also easier to track what you did some time ago.</p>
<p></p>
<p>But in general if you are not outputting 10 of thousands elements from one component like with Kanaroo2 Goals , then it is your solution and solver which should be optimized. Multi-threading is additional option, but you have to know how to do it correctly.</p>
<p></p>
<p></p> The only way to objectively t…tag:www.grasshopper3d.com,2017-11-09:2985220:Comment:18498202017-11-09T15:44:49.764ZAnders Holden Deleuranhttps://www.grasshopper3d.com/profile/AndersHoldenDeleuran
<p>The only way to objectively test performance is through profiling, in C# you might use the <a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx" rel="nofollow" target="_blank">Stopwatch</a> class for this (edit: I recall David having written about this subject, hopefully he'll chime in here). Out of practical <a href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)" rel="nofollow" target="_blank">development</a> …</p>
<p>The only way to objectively test performance is through profiling, in C# you might use the <a rel="nofollow" href="https://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch(v=vs.110).aspx" target="_blank">Stopwatch</a> class for this (edit: I recall David having written about this subject, hopefully he'll chime in here). Out of practical <a rel="nofollow" href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)" target="_blank">development</a> <a rel="nofollow" href="https://en.wikipedia.org/wiki/Separation_of_concerns" target="_blank">concerns</a><a rel="nofollow" href="https://en.wikipedia.org/wiki/Coupling_(computer_programming)" target="_blank"></a>, one might suggest avoiding referencing the Grasshopper SDK as much as possible. That is, for instance using native .NET and RhinoCommon types/data structures as much as possible, and only wrapping these in GH types when necessary (Kangaroo2 follows this principle to a large extent for example). That said, I wouldn't expect there to be much cost involved in using a lot of GH types in the core code.</p>