Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Startup time is long #117

Closed
jbphet opened this issue Jan 20, 2015 · 13 comments
Closed

Startup time is long #117

jbphet opened this issue Jan 20, 2015 · 13 comments
Assignees

Comments

@jbphet
Copy link
Contributor

jbphet commented Jan 20, 2015

The load time for this sim strikes me as excessively long for as simple as it is. This should be profiled and examined and, if possible, the load time should be reduced.

@jbphet jbphet self-assigned this Jan 30, 2015
@jbphet
Copy link
Contributor Author

jbphet commented Aug 25, 2015

This sim is on hold for a while, so I'm unassigning this issue until work resumes.

@jbphet jbphet removed their assignment Aug 25, 2015
@jbphet jbphet self-assigned this Nov 2, 2015
@jbphet
Copy link
Contributor Author

jbphet commented Nov 3, 2015

I just built version 1.0.0-dev.14 (available here: http://www.colorado.edu/physics/phet/dev/html/arithmetic/1.0.0-dev.14/arithmetic_en.html) and measured the startup time on several devices and browsers. It seems to have gotten a bit better, but it still quite long on iPads. My test on each device was to open a new tab, load the sim, then reload it twice, recording the elapsed time from click (or touch) to appearance of the home screen. The collected data is shown in the table below.

Device OS Browser Initial Load (s) Reload 1 (s) Reload 2 (s) Average (s)
Lenovo W520 Win 7 Chrome 4.54 4.41 4.48 4.48
Lenovo W520 Win 7 Firefox 4.96 5.41 5.01 5.13
Lenovo W520 Win 7 IE11 3.95 3.58 3.66 3.73
MacBook Air (Jordan) OSX 10.9.5 Safari 3.03 2.5 2.41 2.65
MacBook Air (Jordan) OSX 10.9.5 Firefox 5.49 5.78 5.48 5.58
iPad 2 (Tycho) iOS 9.0 Mobile Safari 15.51 14.98 16.85 15.78
iPad 3 (Disessa) iOS 9.1 Mobile Safari 15.60 16.18 15.50 15.76

The load time seems pretty decent for all tested cases except for the two iPads. If I can reduce this load time significantly without negatively impacting the other platforms, we should be good to go.

jbphet added a commit that referenced this issue Nov 4, 2015
…nimator so that it doesn't have to copy the whole object for the level selection and workspace nodes, see #117
jbphet added a commit that referenced this issue Nov 4, 2015
…onts instead of recreating a font for each cell, see #117
@jbphet
Copy link
Contributor Author

jbphet commented Nov 4, 2015

Note, mostly to myself: I think the reason that startup time seemed shorter when I started measuring it is that mipmaps are computed on load time in RequireJS mode, but are pre-computed for built versions. For sims (like this one) that use a number of mipmaps, RequireJS load times are quite a bit longer than load times for built sims.

jbphet added a commit that referenced this issue Nov 4, 2015
jbphet added a commit that referenced this issue Nov 5, 2015
…racCell be a zero length string to save on bounds computation time, see #117
@jbphet
Copy link
Contributor Author

jbphet commented Nov 6, 2015

I tested with on the two iPads listed in the table above after making the optimizations reflected in the commits above. The result was that Tycho was down to 10.66 seconds on average and Disessa was at 10.23 seconds. This is a substantial improvement - over 30% - but still not enough. Profiling on Chrome+Win7 shows that the creation of all the text nodes in the cells of the multiplication tables is requiring a substantial amount of time. I'm going to try creating them lazily instead of eagerly.

jbphet added a commit to phetsims/scenery-phet that referenced this issue Nov 9, 2015
…see phetsims/arithmetic#117.  On several trials on OSX, this reduced the creation time to about 1/4 of what it had been.  This was tested on Arithmetic, Balancing Chemical Equations, Fraction Matcher, and Making Tens and no ill effects were observed.
jbphet added a commit that referenced this issue Nov 10, 2015
…leNode in favor of basic layout, see #117.  Also did some code cleanup.
jbphet added a commit that referenced this issue Nov 12, 2015
…single pointer hand in the MultiplicationTableFactorNode, see #117
jbphet added a commit that referenced this issue Nov 12, 2015
… use in the cells, part of the optimization cleanup, see #117
@jbphet
Copy link
Contributor Author

jbphet commented Nov 13, 2015

A lot of optimization has been done, and I'm rerunning the startup time tests to see where we are at. Note that the iPad 2 was upgraded from iOS 9.0 to 9.1 since the first round of testing was performed. The version being tested is 1.0.0-dev.15, and can be found at http://www.colorado.edu/physics/phet/dev/html/arithmetic/1.0.0-dev.15/. The time values were obtained by using a stopwatch app on an iPhone, so they aren't super accurate. This is the same method that was used for the previous data set.

Device OS Browser Initial Load (s) Reload 1 (s) Reload 2 (s) Average (s)
Lenovo W520 Win 7 Chrome 2.33 2.18 2.13 2.21
Lenovo W520 Win 7 Firefox 2.75 2.21 2.18 2.38
Lenovo W520 Win 7 IE11 2.30 1.98 1.98 2.09
MacBook Air (Jordan) OSX 10.9.5 Safari 1.83 1.45 1.35 1.54
MacBook Air (Jordan) OSX 10.9.5 Firefox 2.14 2.10 2.28 2.17
iPad 2 (Tycho) iOS 9.1 Mobile Safari 8.45 6.96 7.66 7.69
iPad 3 (Disessa) iOS 9.1 Mobile Safari 8.98 8.05 8.18 8.40

@jbphet
Copy link
Contributor Author

jbphet commented Nov 13, 2015

For comparison, I just ran the same load test using the recently released Hooke's Law simulation (v1.0.0) on the iPad 2 "Tycho" and got an average of 7.50 seconds, so this sim is very close.

The optimizations have reduced the load times on iPad to around 1/2 of what they were in v 1.0.0-dev.14. I had @ariel-phet do a subjective test on 1.0.0-dev.15, and he felt like the load time was acceptable.

@jonathanolson said that he might look at making some changes in Scenery that would improve load times, since this sim creates a lot of nodes and thus provides a good opportunity to optimize the per-node creation time. I'm assigning the issue to him for now. If he doesn't have time or is unable to find any good optimizations, this issue will be closed since the load time is now in the acceptable range.

@jbphet jbphet assigned jonathanolson and unassigned jbphet Nov 13, 2015
@jonathanolson
Copy link
Contributor

Flame-chart:
arithmetic-flame-1

Initial ~200ms for preloads, ~200ms more for loading require.js modules (and executing them), ~1000ms (1s) for sim object load, ~300ms for Scenery initial display.

I have a ton of notes on potential performance improvements, so I'll be looking at the big offenders (text bounds and stroked shape bounds) and the low-hanging fruit.

@jonathanolson
Copy link
Contributor

@jbphet, a small optimization would be further reducing the number of fonts that the sim uses. It's not terribly significant, so don't worry about it too much. Current list:

10px Arial, sans-serif
10px sans-serif
17px Arial, sans-serif
18px Arial, sans-serif
bold 18px Arial, sans-serif
20px Arial, sans-serif
21px Arial, sans-serif
22px Arial, sans-serif
24px Arial, sans-serif
bold 26px Arial, sans-serif
27px Arial, sans-serif
30px Arial, sans-serif
32px Arial, sans-serif
39px Arial, sans-serif
40px Arial, sans-serif
42px Arial, sans-serif
50px Arial, sans-serif
52px Century Gothic, Futura, sans-serif
54px Arial, sans-serif
90px Arial, sans-serif
bold 120px Arial, sans-serif

@jonathanolson
Copy link
Contributor

onStatic gets called 45290 times on a normal startup, so a Scenery pattern like phetsims/scenery#490 or possibly even an instance-notification pattern would work.

@jonathanolson
Copy link
Contributor

After the above optimizations, Node's constructor's SELF time is 116ms on my Win7/Chrome. Might be creating many hidden-class chains?

@jonathanolson
Copy link
Contributor

I've started to hit diminishing returns. Further investigation would probably be more into how our inheritance pattern might affect hidden classes, and the amount/quality of JS optimization.

Many types of AbstractCell are created (and many of them). It does cause a disabled-optimization on getFillRendererBitmask (along with many deoptimizations). It may be possible to restructure some UI so that we don't display all of the rectangles (but instead one larger rectangle BEHIND grid lines), etc., and that may reduce the Node count significantly (and help with performance).

Current testing:
iPad 3, iOS 9.1
First load: 7.0s
Later loads: ~6.4s

If that's accurate, it's close to 2 seconds off of the previous iPad 3 numbers.

Assigning back to @jbphet for testing. Let me know if you want to work further on improvements.

@ariel-phet
Copy link

@jbphet if the above numbers hold true (~7 seconds on iPad 3) no need for further optimization for sure.

@jbphet
Copy link
Contributor Author

jbphet commented Dec 11, 2015

I just did three trials on an iPad 3 (Disessa) running iOS 9.2, and all trials were less than 8 seconds, average at 7.23 seconds. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants