That is a very cool PG and a really creative way to do that simulation on existing physics engine. Thanks for sharing
I can see how order of operations can affect the net result, but since you take mass into account should be reasonable!! I wrote a physics simulator and wrote it so the order of applying forces like gravity, drag, springs (forces of attraction) could be applied dynamically and in any order, but the order within those did affect results as well especially how an initial state was created if generated from a graph. Fixed time steps were used to make the integration easier to solve. I did an experiment on this recently and ended up relying on Barnes Hut algorithm as a data structure:
Barnes–Hut simulation - Wikipedia
If equilibrium is reached the simulation can stop or be checked less frequently (or new bodies are added, etc.).
I needed a specific QuadTree that stored mass and centerOfMass and that was able to quickly make calculations as well as providing the opportunity to massively reduce math operations in some scenarios - considering the tree needs to be regenerated on each frame. That tree is here:
wammo/quadTree.ts at main · brianzinn/wammo (github.com)
I had wrote a physics plugin for BabylonJS as well that uses that force directed graph project and certainly for n-body simulations especially in space it is specialized. I didn’t have time to take it further, but it would be cool to get that production ready one day!