zaach / jison

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

rewrite followSets() to drastically improve compile performance #408

Open cosmicexplorer opened 1 week ago

cosmicexplorer commented 1 week ago

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 https://github.com/jashkenas/coffeescript/pull/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).