phetsims / molecule-polarity

"Molecule Polarity" is an educational simulation in HTML5, by PhET Interactive Simulations.
GNU General Public License v3.0
2 stars 6 forks source link

RealMoleculesScreenView is doing unnecessary work #65

Closed pixelzoom closed 7 years ago

pixelzoom commented 7 years ago

We're releasing Molecule Polarity 1.0.0 without an implementation of the Real Molecules screen, see #27. But in the meantime, it is still doing a lot of unnecessary work, which will impact startup time.

RealMoleculesScreenView constructor currently looks like this:

function RealMoleculesScreenView( ... ) {

  ScreenView.call( ... );

  // create a whole bunch of Nodes and add them to rootNode

  if ( MPQueryParameters.realMolecules ) {
    this.addChild( rootNode );
  }
  else {
    this.addChild( new UnderDevelopmentPlane( this.layoutBounds ) );
  }
}

Better would be:

function RealMoleculesScreenView( ... ) {

  ScreenView.call( ... );

   if ( !MPQueryParameters.realMolecules ) {
    this.addChild( new UnderDevelopmentPlane( this.layoutBounds ) );
  }
  else {
    // create a whole bunch of Nodes and add them to rootNode
    this.addChild( rootNode );
  }
}
pixelzoom commented 7 years ago

Creating the model (RealMoleculesModel) is lightweight, so it's OK to do that and not use it. The significant cost is in creating the view.

pixelzoom commented 7 years ago

Done, tested with and without ?ea&realMolecules.

pixelzoom commented 7 years ago

@zepumph FYI, since you're in the process of code review.