Skip to content

Make generated parsers smaller #35

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

Closed
dmajda opened this issue Aug 14, 2011 · 5 comments
Closed

Make generated parsers smaller #35

dmajda opened this issue Aug 14, 2011 · 5 comments
Assignees
Labels
Milestone

Comments

@dmajda
Copy link
Contributor

dmajda commented Aug 14, 2011

Generated parsers are too big:

dmajda@inuit:~/Programování/Projekty/PEG.js/pegjs$ bin/pegjs examples/arithmetics.pegjs 
dmajda@inuit:~/Programování/Projekty/PEG.js/pegjs$ bin/pegjs examples/css.pegjs 
dmajda@inuit:~/Programování/Projekty/PEG.js/pegjs$ bin/pegjs examples/javascript.pegjs 
dmajda@inuit:~/Programování/Projekty/PEG.js/pegjs$ bin/pegjs examples/json.pegjs 
dmajda@inuit:~/Programování/Projekty/PEG.js/pegjs$ wc -c examples/*.js
  13327 examples/arithmetics.js
 429010 examples/css.js
 610664 examples/javascript.js
  54518 examples/json.js
1107519 celkem
dmajda@inuit:~/Programování/Projekty/PEG.js/pegjs$ wc -c src/parser.js 
103838 src/parser.js

They should be much smaller, ideally without sacrificing performance.

@ghost ghost assigned dmajda Aug 14, 2011
@ceymard
Copy link

ceymard commented Aug 15, 2011

I am not sure it would be that useful to make generate smaller parsers an important issue : Closure Compiler or other minifiers do a good job at that.

Performance ought probably to be the most important aspect of pegjs, imho.

@dmajda
Copy link
Contributor Author

dmajda commented Aug 20, 2011

@pwipwi: For some people the most important thing is performance, for some size. It totally depends on usage (web/Node.js, small inputs vs. big inputs, simple grammars vs. complex grammars, etc.). Minifiers can help of course, but not everybody uses them and they also can't compress the code structurally (much).

The size improvements shouldn't primarily be things like removing whitespace and making all identifiers just one letter long (that's the job for minifiers). They should be mostly removing useless/duplicate code and making it simpler where possible.

I am also thinking about a state-machine/bytecode-based approach instead of generating JavaScript code directly — that would probably help a lot here.

@ceymard
Copy link

ceymard commented Aug 20, 2011

Agreed.

@dmajda
Copy link
Contributor Author

dmajda commented Sep 1, 2011

Fix to reset parser positions when action returns |null| made generated parsers somewhat larger, but today's variable handling rewrite made them almost 9% smaller.

@dmajda
Copy link
Contributor Author

dmajda commented Jan 1, 2013

This was fixed by the code generator rewrite.

More optimizations are possible but they should be tracked separately elsewhere.

@dmajda dmajda closed this as completed Jan 1, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants