rewrite followSets() to drastically improve compile performance #408
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
I am looking to introduce some changes to the CoffeeScript Jison grammar. In doing so, I found that it took surprisingly long to generate. I added some grammar compile performance measurements to the CoffeeScript build system in jashkenas/coffeescript#5473, and was wondering if there was a way to improve them.
Solution
I spent quite a while rewriting a lot of the code (see e.g. https://github.com/zaach/jison/compare/master...cosmicexplorer:jison:performance-work-for-coffeescript?expand=1), and while I think a lot of that would be useful to the project, I found that the performance could be vastly improved by modifying a single method:
followSets()
, which performs a fixed-point calculation.Result
There should be no change in functionality or compatibility, but many compiles should run much faster. The CoffeeScript parser build time goes from ~12 seconds down to ~4 seconds on my laptop with this change (3x improvement).