Structural optimization takes longer and longer - Dynamo and RSA

I am trying to adapt the routine used to optimize structures available in this presentation by Dieter Vermeulen (Dynam(o)ite Your Design for Engineers | Autodesk University). I’m getting results, but something is making my calculation too slow. In my case, the more structures are calculated, the longer the calculation time between one structure and another, which is incredibly time consuming for a hundred structures.

I am applying some Python code to extract some values from RSA and I believe that this is taking the calculation longer. Something is probably taking up memory space during calculations, but I don’t know how to clean it up. I am sending images as an example of the codes I am implementing. Can you identify something that is making this execution so heavy? I already tried to clear the variables, but it didn’t solve the problem.

One place I see if that you call RN.Get(i).Number twice. Don’t know how big or fast that iteration is, but I may be wise to call it once and store the value. Other than that there isn’t much else going on to really speed up except maybe limiting what libraries your loading rather than from RobotOM import *, but i don’t know the package to say that will work in your case.

Thank you for your help

I didn’t call the function twice, I just printed it wrong

I am not very good with Python. How could I limit these libraries?