phetsims / plinko-probability

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

CPU overload when sim is running in Firefox #48

Closed amanda-phet closed 7 years ago

amanda-phet commented 8 years ago

Test device: Macbook pro

Operating System: OS X 10.10.5

Browser: Firefox

Problem description: CPU overloaded when the tab with the sim is open. If I switch to another tab it calms back down.

Steps to reproduce: Open sim in firefox and keep it open.

Severity:

Screenshots:

screen shot 2016-07-06 at 12 00 48 pm

Troubleshooting information (do not edit): Name: ‪Plinko Probability‬ URL: http://www.colorado.edu/physics/phet/dev/html/plinko-probability/1.0.0-dev.5/plinko-probability_en.html Version: 1.0.0-dev.5 2016-06-27 15:36:39 UTC Features missing: touch Flags: pixelRatioScaling User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:47.0) Gecko/20100101 Firefox/47.0 Language: en-US Window: 1119x569 Pixel Ratio: 2/1 WebGL: WebGL 1.0 GLSL: WebGL GLSL ES 1.0 Vendor: Mozilla (Mozilla) Vertex: attribs: 16 varying: 16 uniform: 1024 Texture: size: 4096 imageUnits: 16 (vertex: 16, combined: 16) Max viewport: 16384x16384 OES_texture_float: true Dependencies JSON: {"assert":{"sha":"7d27130a","branch":"master"},"axon":{"sha":"b71cc337","branch":"master"},"babel":{"sha":"0ce3b9c8","branch":"master"},"brand":{"sha":"f0b1f7da","branch":"master"},"chipper":{"sha":"e044eccd","branch":"master"},"dot":{"sha":"c9c05a5a","branch":"master"},"joist":{"sha":"fa5db70c","branch":"master"},"kite":{"sha":"dce9765e","branch":"master"},"phet-core":{"sha":"c48bf320","branch":"master"},"phetcommon":{"sha":"35ef94ad","branch":"master"},"plinko-probability":{"sha":"af3b08d0","branch":"master"},"scenery":{"sha":"4476eb95","branch":"master"},"scenery-phet":{"sha":"52b783d9","branch":"master"},"sherpa":{"sha":"77506dc3","branch":"master"},"sun":{"sha":"0d7e743b","branch":"master"},"tandem":{"sha":"b3c68afa","branch":"master"}}

veillette commented 8 years ago

I have noticed something similar in chrome. We may need to do some regression testing because it did perform well in chrome in the past.

phet-steele commented 8 years ago

I took some numbers of % CPU usage in both Chrome and Firefox. Tests were recorded on the lab screen while letting the sim drop endless balls with either the Balls option or None option checked:

Chrome Firefox
Idle 7% 15%
Running (Balls) 8% 24%
Running (None) 9% 100%-160%

These tests were run in 1.0.0-dev.6, so the long and short of it is yes, Firefox still hogs the CPU. There was not a noticeable performance drop, only that my computer was getting hot. Switching to another tab does indeed calm Firefox down.

pixelzoom commented 8 years ago

https://github.com/phetsims/plinko-probability/issues/62 may be responsible for this. The sim is continuously calling paintCanvas, even when nothing on the screen is changing.

pixelzoom commented 7 years ago

After fixing #62, here's what I see with 1.0.0-dev.12. This is on the "Lab" screen, with continuous balls. Firefox 48.0.1, MacBook Pro (model 5,3), Mac OS X 10.11.6, 2.66 GHz Intel Core 2 Duo. I used Activity Monitor to monitor CPU usage.

Hopper mode Firefox %CPU
Ball 43%
Path 43%
None 85%

Things to investigate:

(1) Why does "None" use more CPU than "Path"? I would expect it to be the same or slightly less. The display is identical, expect it's not drawing the path.

(2) How does CPU usage compare to other PhET sims? Is there something unique to this sim, or are PhET sims CPU hogs when run on Firefox?

ariel-phet commented 7 years ago

As a quick data point @pixelzoom Function builder (slamming cards through the triple builder on the patterns screen) is around 1-3% CPU usage for me on Win 7 64 bit FF

Edit total CPU around 5 or 10 percent average

ariel-phet commented 7 years ago

1 or 2% for rutherford scattering, with around 15-20% total CP

pixelzoom commented 7 years ago

@ariel-phet What %CPU do you see for this Plinko on Win 7 64 bit FF?

On Mac OS X 10.11.6 + FF 48.0.1, I see similar CPU issues with other PhET sims.

• Rutherford Scattering: 97% on first screen, "nucleus" view, "Show traces" checked • Wave On A String: 110% when shaking the wrench • Color Vision: 45% on "RGB Bulbs" screen with all lights at 100% • Energy Skate Park Basics: 28% on first screen, skater in motion, pie chart and bar graph visible

So it looks to me like Plinko CPU usage is similar to other sims with Mac + Firefox.

ariel-phet commented 7 years ago

Ah for Plinko on Win 7 64 bit (FF) I am seeing 5-10% total CPU for plinko just standing aorund or running (not much difference)

Sounds like we just need to move this to a general WTF is up with PhET and Mac + FF

I could also have @oliver-phet check what Mac + FF is in terms of our userbase (possibly very small) and perhaps we drop FF support for Mac

oliver-phet commented 7 years ago

YTD: Firefox (all OS): 8.06% Firefox (Mac-only): 1.14%

pixelzoom commented 7 years ago

So, it sounds like I should:

(1) Take a look at why "None" is so much more CPU intensive than "Path", but otherwise don't worry about it.

(2) Create a general issue for Mac + FF performance. @ariel-phet Any thoughts on which repo would be the appropriate place for that issue?

ariel-phet commented 7 years ago

@pixelzoom that is such a general issue, and since we don't know the root...I would say tasks or phet-info (dealers choice)

pixelzoom commented 7 years ago

Notes to self:

• Do a Google search for "firefox cpu usage mac". • See https://support.mozilla.org/en-US/questions/1074722

pixelzoom commented 7 years ago

Perhaps 'None' is more CPU intensive than 'Paths' because it creates balls 3.3x more frequently, and is therefore updating the histogram 3.3x more frequently.

LabModel, line 104:

case 'path':
  ...
  this.ballCreationTimeInterval = 0.050; // 50 milliseconds if we are seeing paths
  break;

case 'none':
  ...
  this.ballCreationTimeInterval = 0.015; // 15 milliseconds if nothing is being shown
  break;
pixelzoom commented 7 years ago

https://github.com/phetsims/plinko-probability/issues/48#issuecomment-246801710 is indeed the case - 'None' is using more CPU than 'Path' because it's updating the histogram 3.3x more often. I I use the same ballCreationTimeInterval (0.050) for 'Path' and 'None', then 'None' uses slightly less CPU than 'Path'.

But something else very odd - I'm no longer seeing the CPU usage problem! With the same test platform as in https://github.com/phetsims/plinko-probability/issues/48#issuecomment-246029192 (Mac OS X 10.11.6 + FF 48.0.1), the CPU usage is now dramatically lower:

Hopper mode Firefox %CPU
Ball 15%
Path 6%
None 16%

No idea why this has suddenly changed.

samreid commented 7 years ago

I tested http://www.colorado.edu/physics/phet/dev/html/plinko-probability/1.0.0-dev.5/plinko-probability_en.html with Firefox 48.0.1 on my Macbook Air running OS X 10.11.6 and observed CPU fluctuating between 20%-50% (out of a max of 200%), summing up both "Firefox" and "Firefox web content". When I switched to a different tab, there was negligible CPU usage. The CPU usage seems about the same whether the balls are falling or not.

pixelzoom commented 7 years ago

Hmmm... What seems to have changed is what is displayed in Activity Monitor. Now I'm seeing 2 processes: Firefox, Firefox Web Content. And the big CPU usage has moved from Firefox to Firefox Web Content. I didn't start Activity Monitor any differently than previous tests. And (I thought) that my previous tests were with the same FF 48.0.1.

pixelzoom commented 7 years ago

From https://developer.mozilla.org/en-US/Firefox/Multiprocess_Firefox:

In current versions of desktop Firefox, the entire browser runs in a single operating system process. In particular, the JavaScript that runs the browser UI (also known as "chrome code") runs in the same process as the code in web pages (also known as "content" or "web content").

Future versions of Firefox will run the browser UI in a separate process from web content. In the first iteration of this architecture, all browser tabs will run in the same process and the browser UI will run in a different process. In future iterations, we expect to have more than one content process.

pixelzoom commented 7 years ago

Multiprocess Firefox is apparently new in version 48. From https://blog.mozilla.org/futurereleases/2016/08/02/whats-next-for-multi-process-firefox/:

This first phase of enabling our multi-process architecture is making its way to some of our Firefox 48 users starting this week. This is the biggest change we’ve ever made to Firefox, so we’re rolling it out slowly. For Firefox 48, we’re only enabling it for classes of users that our testing shows it works well for and to begin with, we’ll only enable it for 1% of those users so we can check on the stability and engagement data and make sure nothing new and bad is showing up. After that initial period, if all looks well, we’ll ramp up to 100% of those users, which will be about half of all Firefox 48 users.

pixelzoom commented 7 years ago

From https://wiki.mozilla.org/Electrolysis:

If you're using Firefox 48 or later, you might be using e10s already. Check about:support and look for a number higher than 0 in the "Multiprocess Windows" entry. If you would like to opt-in, open about:config and toggle browser.tabs.remote.autostart to true. On your next restart, e10s should be active.

My entry shows Multiprocess Windows: 1/1 (Enabled by default), so looks like I've been selected to be a guinea pig. Not sure how that happened, it wasn't anything that I recall opt'ing into.

pixelzoom commented 7 years ago

"e10s" by the way, is Mozilla's abbreviation for "Electrolysis", the project name for multiprocess FF.

pixelzoom commented 7 years ago

Hmmmm... I was going to hypothesize that there's a problem with FF's new multiprocess feature on Mac. But that feature appears to have been introduced in FF 48, and this issue was original reported for FF 47.

pixelzoom commented 7 years ago

Tracking the general issue of high CPU usage on Mac+FF in https://github.com/phetsims/tasks/issues/695.

Closing this issue, since there's nothing sim-specific to be done.