in the Add Action window for an object, down at the bottom is a Z-order section.
you can move an object to the top or bottom, or move it next to another selected object (in front or behind).
Those functions should give you the ability to easily order your objects any way you want, The For Each (Ordered) performs extremely quickly for me, so it could be some other factor that is killing your performance.
Every object has a Zindex value you can access directly to figure out its depth - there are lots of ways to make it work.
like I said above, the main trick is to avoid ambiguous situations when comparing one object to another of the same type ( object.Zindex > object.Zindex doesn't make sense because C2 can't tell which specific instance is which). So, you have to pick the first object by the type, and the second one by a family (so you end up comparing object.Zindex > familyObject.Zindex) those could be any two instances you want, but now C2 knows which one is being compared to another of the same type,