Rhino 7 behaving slower?

Rhino 7 looks for me like it is behaving slower with Grasshopper Python and C#
I do not know if it is a problem with my computer or what ? but I wonder if someone else feels the same ? could someone test this Gh script with a nested for loop and let me know. I am afraid I did something wrong? But Rhino and Gh crash or take too much time to update each time I move a slider! How could I fix this? thanks in advance!

GridPoints-PointAttractor-PythonToC#.gh (17.4 KB)

For the Python side of things, you can optimize a lot! I got it down to 65ms for your current input parameters with only a few changes. At this rate, the component remains fully responsive when inputs are updated.

Screenshot 2021-02-01 at 20.47.34

You create 1000 spherical surfaces (10 x 10 x 10), which is expensive. For lots of geometry I’d always go with meshes instead (except for cases where n.u.r.b.s geometry is absolutely needed)!

Apart from that, you store 1000 distance values and points that you don’t even need at the moment, and can get rid of.

Also, since you don’t need the exact distance value - you scale it by an arbitrary number to get the radius of each sphere - simply replace it by the distance squared. To get the distance a square root calculation is performed (cf. Pythagoras), which is expensive and slow. Getting the squared distance is much faster.

Lastly, I use RhinoCommon - the API - instead of rhinoscriptsyntax, which is probably also faster, simply because rhinoscriptsyntax is another layer on top of RhinoCommon.
This probably makes only a very small difference though.

import Rhino.Geometry as rg

XSTEP = 1.0
YSTEP = 3.0
ZSTEP = 3.5

a = []

for i in xrange(x):
    for j in xrange(y):
        for k in xrange(z):
            pt = rg.Point3d(i * XSTEP, j * YSTEP, k * ZSTEP)
            dist_sq = pt.DistanceToSquared(attractor)
            a.append(
                rg.Mesh.CreateFromSphere(rg.Sphere(pt, dist_sq * scale), 8, 8)
                )

In IronPython, you can also use the faster xrange(), over range(). (In CPython 3, range()is even faster.)

Another thing to consider in Grasshopper is that overuse of scribbles and groups usually make the canvas laggy and slow.

GridPoints-PointAttractor-Python2.gh (8.6 KB)