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

Fix RangeError, and make it a teeny bit faster #8

Merged
merged 2 commits into from
May 29, 2015

Conversation

eevee
Copy link
Contributor

@eevee eevee commented May 29, 2015

The RangeError also happens with the 2.1.0 release; I think this commit should apply cleanly there, though.

Times are all load time of Counterfeit Monkey (as given in the console) averaged over three attempts, in current Chromium and current Firefox.

2.1.0 release, after fixing RangeError:
Chromium: 33.758s
Firefox: 16.190s

noeval, after fixing RangeError:
Chromium: 18.751s
Firefox: 22.590s

noeval, after speeding up fetch_search_key:
Chromium: 16.559s
Firefox: 21.783s

So, seems to match your observations — Chrome is significantly faster, Firefox is significantly slower. Chrome started out doing really badly, though.

I'm not quite sure where to go from here; the VMs are just optimizing differently, and now the bulk of the time is in a handful of functions so it's difficult to see what low-hanging fruit remains. Chromium blames 28% of the time on execute_loop and 18% on pop_callstub; Firefox blames 42% (!) on execute_loop and 19% on all the dynamically-generated functions in aggregate.

Just for fun, my original branch, which is kind of a mess:
Chromium: 11.934s
Firefox: 16.242s

The only significant difference I can think of is that I made a VM "class", with all the functions on its prototype, and then passed a single instance to generated functions as a regular argument. It's possible that both JavaScript VMs are just much better at dealing with this pattern, since it's how new types are generally implemented.

eevee added 2 commits May 28, 2015 17:01
There's a limit to how many arguments a JavaScript VM will accept for a
single function call, and piping large blocks of the game image through
String.fromCharCode.apply appears to violate that limit.
Setting the length of an array is surprisingly expensive -- instead,
just return a new literal array.  Also use native array slicing when
possible.
erkyrath added a commit that referenced this pull request May 29, 2015
Fix RangeError, and make it a teeny bit faster
@erkyrath erkyrath merged commit f98d7a3 into erkyrath:noeval May 29, 2015
@erkyrath
Copy link
Owner

Note to observers: this bug manifests itself when playing a game with large images loaded from a gblorb.js file (not the fast-loading path). Counterfeit Monkey shows it. Imagetest and Sensory Jam do not, because all their image files are tiny.

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

Successfully merging this pull request may close these issues.

None yet

2 participants