lezer-parser / lezer

Dev utils and issues for the Lezer core packages
33 stars 1 forks source link

Speeding up build parser #42

Closed nchen63 closed 11 months ago

nchen63 commented 11 months ago

I have a grammar that takes a long time to build. When profiling I see most of the time (160 seconds) is spent in canMergeInner in automaton.ts.

marijnh commented 11 months ago

There are often small changes you can make to make a grammar generate dramatically fewer states. Sometimes they are straightforward, such as avoiding rule count blowup by refactoring rules to not have too many optionals (see this patch). In other cases, unfortunately, they are really non-obvious, requiring a lot of insight into what the parser generator will do with your grammar.

If you can find an elegant way to optimize that function, I'd be open to that. But the awkward thing is that, if it builds the table itself, it's going to either have to cache those somewhere, or generate it again and again as it is called on different states. Maybe a lazily-computed property on the state objects would work.

nchen63 commented 11 months ago

Can you tag/release the fix?

marijnh commented 11 months ago

I've released a version 1.5.1