Join GitHub today
Significantly decrease parser file size by compacting parser table #234
This pull request nearly halves the gzipped size of generated parsers.
The largest part of a Jison-generated parser is its
Two kinds of patterns occur frequently in such a table:
I tackled the first case by storing frequently occurring arrays into temporary variables:
I tackled the second case by creating such objects with an auxiliary function
That also leads to new long arrays with numbers, which can be optimized under the first case.
Not only does this lead to a significantly decreased filesize of the parser, it also leads to less memory usage, as it avoids having multiple copies of the same array in memory.
To support such chunks of reusable code, the
A parser I am working on benefited significantly from the new table generation function:
The decrease from 36kb to 19kb is a 47% reduction.
There are two immediate cases left for further optimization:
Yihaa, thanks for merging! Any chance you could publish a new version to npm?
I plan to have a look next week at the other optimizations suggested in my comment above. Probably they won't be as spectacular, but we might still shave a few kilobytes off.
Pull request #235 implements the suggestion “objects with almost all identical values”.
I also tried “recognition of sublists”, but this doesn't bring the gzipped size down (as expected); it also doesn't significantly change the minified version. Therefore, I haven't included it.
Hi, this looks really cool and I'm trying to understand the impact on the development process. The build script for your SPARQL parser calls jison directly:
Should I see a call to a minimizer which would replace identical sequences in the generated table?