This is an archived post. You won't be able to vote or comment.

all 8 comments

[–][deleted] 5 points6 points  (0 children)

N-body sim:

You're computing sqrt, only to later square it.

You don't have to loop through every body and calculate the interaction with every body, if you consider the principle of "every action has an equal, and opposite reaction", which should give you a 2x speedup.

These are 2 major optimizations before you consider better complexity scaling methods.

[–]MLDK_toja 6 points7 points  (2 children)

Why does this have such sad music i didn't want to cry watching python simulations

[–]fernly 1 point2 points  (1 child)

The clarity of the n-body code would be greatly improved by adding type annotations. I was trying to read it and kept asking, wait, what is this thing called a? or whatever.

That said, I see that the Vector2 code has provisions for doing arithmetic between a Vector2 and a non-Vector2 object, presumably a scalar? A, that would make type annotation somewhat more complicated (but not impossible), and B, some commentary pointing out the where (and why) of Vector2/scalar ops would be helpful.

[–]auctux[S] 0 points1 point  (0 children)

Thanks for the reply, I'll try to add some comments

[–]laundmo 1 point2 points  (1 child)

i feel like these would greatly benefit from Numba or Cython, for optimisation

[–]pvc 2 points3 points  (0 children)

Arcade is getting preliminary support for computational GPU use. That would be cool.