You are using many procs like
proc sum(l: Vector, r: Vector): Vector =
Vector(x: l.x + r.x, y: l.y + r.y, z: l.z + r.z)
Run
Of course that functional style can be very expensive. You may try marking that
proc with {.inline.} pragma or compile your program with gcc option -flto or
both.
The fact that your Vector is a reference to object is not really helpful for
performance of course, that is one level of indirection, and each call to a
proc like sum() is a new heap allocation.
Maybe the compilers can optimize away all that overhead -- I don't think so.
There may exist much more to optimize in your code, I have not really looked at
it, but these points are obviously.