zaach / jison

Bison in JavaScript.
http://jison.org
4.36k stars 450 forks source link

Fix performance bug: Bad value context for argument value #332

Open NightRa opened 8 years ago

NightRa commented 8 years ago

Using arguments in a dynamic way in a function leads to the JIT (v8) not optimizing the whole function, with the error: "Bad value context for argument value". See https://github.com/GoogleChrome/devtools-docs/issues/53#issuecomment-51941358 and Note gist.

This commit wraps the parse function with handling of arguments, and calls into the regular function with the args array, and now it can be optimized.

This fix improved performance almost 2x for me, from 17s to 9s. (for 500Kb of text so there's still room for improvement)

GerHobbelt commented 8 years ago

@NightRa : nice catch, this one! Since you seem interested in maximum performance jison parsers, you may be interested in https://github.com/GerHobbelt/jison/commit/d2f8af7886ebda016b1e975fe94414b4134f6d5d (with some more performance-related work done in https://github.com/GerHobbelt/jison/commit/e44add313edf572f0c4f35f4862c08ab7aee41c8 ).

The thought there is that

==> that made me wonder: "Why don't we take the %parse-params argument list and inject straight away into the code instead of messing with this arguments semi-array at all?" and those two referenced commits above are the result.


Thanks you for your work; I had not realized the high cost of arguments+slice in the parser core yet. 👍