hunar4321 / particle-life

A simple program to simulate artificial life using attraction/reuplsion forces between many particles
MIT License
2.98k stars 297 forks source link

x5 JS Performance Improvement #27

Closed dangarfield closed 1 year ago

dangarfield commented 1 year ago

You can simply improve performance by at least 4 or 5 times by using arrays / matrices instead of relatively expensive object calls.

This went from 7 fps to 30 fps comfortably on my machine with no functional change.

It is a little less intuitive to read, however I believe the performance benefit is significantly improved.

I will also experiment with GPU calculations now that the atom definitions are all number matrices. It makes it relatively trivial to add this functionality now.

dangarfield commented 1 year ago

I've also added a fi to ensure that no atoms escape the boundaries as described here - https://github.com/hunar4321/particle-life/issues/4

hunar4321 commented 1 year ago

That is really cool! Thanks