erkyrath / quixe

A Glulx VM interpreter written in Javascript
http://eblong.com/zarf/glulx/
MIT License
169 stars 33 forks source link

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

Closed eevee closed 9 years ago

eevee commented 9 years ago

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.

erkyrath commented 9 years ago

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.