When I use a C# Script component, my canvas gets slow, the script itself is also very slow as if something was running on background. All right click menu are not appearing unless I do a screenshot or wait a certain amount of time.
The problem spreads to my whole computer until I restart the whole computer. I don’t know if it is a graphic problem, or a calculation problem.
I’ve checked, my CPU is not overload, the driver are all updated.
I’m working with Rhino 6 (v1.50)
The size of my GH file is 206 Ko
Has anybody dealed with the same problem ?
Many thanks
Even a very small file can create hundreds or thousands of geometry bits that will bring any computer to its knees, depending on what it’s trying to do.
Thanks for the reply, indeed, I’ve encountered this kind of problem. I’m using the Bifocal widget to optimize my definitions. So it is not coming from here. It is my first debugging step when the definition is slowing down.
Here it is not just a slowing down, it is also a graphic problem with the drop down menu, even outside Grasshopper (And I’m sure that Grasshopper is the source of the problem)
Hi @Paul.D, is there any chance of you removing all the non-essential stuff from that file. If you can save it under a different name and just internalise the data as close as possible to the relevant component, then delete all non-relevant components, it would really help.
The file as it stands contains many C# components as well as clusters, and I’m not sure which one is the one you’re asking about.
Okay, I had to set a point manually for ‘Position of Bow’ as the telepathy component it was attached do didn’t link to anything. But I’m not seeing a slow down, either on the Canvas, or the Rhino viewports, or the UI. Menus are appearing as expected as well.
There are two ways in which a process (any process) can slow down the entire OS:
It can hog too many processing resources (CPU, GPU)
It can hog too many storage resources (RAM, Disc, …)
If the problem persist beyond the complete shutdown of the application, it’s most likely to be an issue with RAM. The program requires so much memory storage, that it forced a lot of data which is needed by other processes from the RAM (which is fast) to the disc (which is slow). This is usually called ‘paging’ and it will keep interfering with the performance of the computer after the offending application terminates, because all the data is still on the disc and it takes time for the OS to clear out the RAM and move the data back. This can take minutes in my experience, and usually doesn’t start until the memory is accessed again.
Given that conjecture, I’m looking at the scripts in your file to see if any of them are liable to lay claim to ever increasing amounts of memory. I’ll let you know what I find.
Incidentally, while I’m at it, I figured I’d post some tips about C#. I noticed your point sorting code is incredibly inefficient, traversing and updating the entire collection for each individual next sorted point.
private void RunScript(List<Point3d> points, string coordinate, ref object sortedPoints)
{
System.Comparison<Point3d> comparer = null;
if (coordinate.Equals("x", StringComparison.OrdinalIgnoreCase))
comparer = SortX;
else if (coordinate.Equals("y", StringComparison.OrdinalIgnoreCase))
comparer = SortY;
else if (coordinate.Equals("z", StringComparison.OrdinalIgnoreCase))
comparer = SortZ;
if (comparer == null)
{
Component.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "'coordinate' input must be either 'x', 'y', or 'z'.");
return;
}
points.Sort(comparer);
sortedPoints = points;
}
private int SortX(Point3d a, Point3d b) { return a.X.CompareTo(b.X); }
private int SortY(Point3d a, Point3d b) { return a.Y.CompareTo(b.Y); }
private int SortZ(Point3d a, Point3d b) { return a.Z.CompareTo(b.Z); }
Do note that there’s a slight functional difference between the old and this new code. The old sorter is stable, whereas the new one is not. If you have two points with exactly equal sorting keys, their ordering in the sorted list is now pretty much random, whereas before it was not.
I found bupkis. Other than the O(n^2) sorting algorithm I commented on before, there’s nothing in any of the C# scripts that would suggest either an excessive use of processing or storage resources.
I’ve opened your original file again now that I have the Telepathy plugin installed, and it too runs reasonably well. A little over 30fps of Canvas redraw speed, a little over 60 fps Rhino viewport redraw speed.
Although since I don’t have the referenced shapes from the 3dm file, the file probably doesn’t do much either.
Hi @Joseph_Oster it’s a plugin I’ve received some recommandations about. When you have some big definitions it helps you connect your component without having a wire mess and looking for your component everytime.
I have many big definitions and very rarely feel the need to hide any wires. When I do, I use the built in ‘Wire Display | Hidden’ feature which has two benefits:
When I touch a component at either end of a hidden wire, the wire is displayed, making it easy to understand connections.
It doesn’t require a plugin, making the model accessible to everyone.
Very interesting, My knowledge of C# is new, and I’m still learning as it is not my primary activity.
I’ll look into it, to understand how it is working. Thanks for sharing
That is really odd. I’ve restart the computer, and now everything came back to normal. I’m trying to recreate the situation in which I was to see what could trigger such a problem.
It is not the first time I’ve had this problem with C# script.
This is pretty much everything I’ve installed in the computer.
I’ve noticed no increase in my memory consumption. I’ll look into different situation to see what could trigger the problem