phetsims / fluid-pressure-and-flow

"Fluid Pressure and Flow" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
8 stars 5 forks source link

About 90% CPU taken up in propagateParticles. How to speed up the performance? #140

Open samreid opened 10 years ago

samreid commented 10 years ago

The simulation is running somewhat slow on my desktop and very slow on the iPad3. I noticed about 90% CPU taken up in propagateParticles. We should discuss what options we have available to speed up the computation.

Some possibilities:

  1. Many methods are creating and throwing away many Vector2. In the Java version this was fast enough, but we may need to curtail allocations in the HTML5 version through the use of (a) component-wise math (b) pass-by-reference or (c) pooling. Not sure how much this will speed things up, and it probably will decrease the maintainability of the code, so should not be taken lightly (we should make sure any performance benefit is worth the tradeoff in readability).
  2. Another place to look will be to see if there is duplicated work. For instance, perhaps some values don't need to be computed multiple times during a step, or can be cached from one step to the next.

Any other ideas about how to improve performance for this sim? Let's discuss.

notsiddhartha commented 10 years ago

Two major things affecting the performance in HTML5 sim:

  1. Number of particles (velocity calculation per particle)
  2. Number of cross sections

After reducing the number of cross sections, I now get about 30 fps on desktop and 14 fps on iPad3 at the slowest flow rate and initial pipe shape.

Need to investigate further on caching computed values.