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.

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)