phetsims / bending-light

"Bending Light" is an educational simulation in HTML5, by PhET Interactive Simulations.
http://phet.colorado.edu/en/simulation/bending-light
GNU General Public License v3.0
8 stars 8 forks source link

Mutate the LightRayNode instances instead of destroy/create in Screen 1 and Screen 3 #159

Closed samreid closed 9 years ago

samreid commented 9 years ago

The First screen of Bending Light would go much faster if the LightRayNodes were mutated instead of destroyed/created at each frame. There is a call to set the start and end in one call: setLine. The create/destroy pattern is a direct port from the original Java but now this needs to be improved to have higher performance.

@ariel-phet who would you like to work on this?

ariel-phet commented 9 years ago

Hey @samreid why don't you go for this improvement

samreid commented 9 years ago

I reviewed the original specification given to Actual Concepts and noted that it said:

For “one color” light rays, two strategies should be implemented:

  1. scenery Line node instances should be pooled and reused (mutated) to avoid overhead in recreating and garbage collecting them.
  2. scenery Line node instances should be created and garbage collected for each change in lines The above strategies should be compared for performance on at least iPad/Safari (on iOS8), OSX/Chrome and Win/Firefox. If the performance is within 5%, then the simpler algorithm (2) should be used, otherwise the faster algorithm should be used.

@ChandrashekarBemagoni I would recommend the following changes specifically:

  1. For the model for the first and 3rd screens, create 3 ray view instances. One for "incoming" "transmitted" and "reflected". Reuse these view elements when the model changes instead of recreating them in each frame. Set their positions using setLine() and set their opacity/color with setOpacity() and setFill().
  2. For the Prisms screen, please try pooling and reusing the scenery Line instances to improve performance. Please see phet-core/js/Poolable.js for our pooling support.
samreid commented 9 years ago

Actually, from https://github.com/phetsims/bending-light/issues/162 it seems like it would be even better to use canvasnode/webglnode to show all of the light rays in the Prisms screen.

So for this issue please focus on recommendation (1) from above, which is:

For the model for the first and 3rd screens, create 3 ray view instances. One for "incoming" "transmitted" and "reflected". Reuse these view elements when the model changes instead of recreating them in each frame. Set their positions using setLine() and set their opacity/color with setOpacity() and setFill().

samreid commented 9 years ago

It looks like the canvas node solution I'm developing for #162 will work well here. I'll reassign the issue to me.

samreid commented 9 years ago

Since we are using canvas to render all the solid light rays from #162, I have removed LightRayNode.js and will close this issue.