metadevpro/ts-pegjs

ts-pegjs 4.2.1 is significantly slower than ts-pegjs 3.0.0

nene opened this issue · 2 comments

nene commented

I'm upgrading from Peggy 2 to 3 and accordingly from ts-pegjs 3 to 4, but discovering that the performance of ts-pegjs has significantly dropped.

Previously with Peggy 2 and ts-pegjs 3:

Pass check.reportUndefinedRules took 16ms
Pass check.reportDuplicateRules took 1ms
Pass check.reportDuplicateLabels took 4ms
Pass check.reportInfiniteRecursion took 69288ms
Pass check.reportInfiniteRepetition took 4ms
Pass check.reportIncorrectPlucking took 1ms
Pass transform.removeProxyRules took 5ms
Pass transform.inferenceMatchResult took 23ms
Pass generate.generateBytecode took 61ms
Pass generate.generateTS took 117ms
✨  Done in 71.75s.

(I do have an excessively large grammar file of about 6000 LOC)

Now with Peggy 3 and ts-pegjs 4:

Pass check.reportUndefinedRules took 16ms
Pass check.reportDuplicateRules took 1ms
Pass check.reportDuplicateLabels took 5ms
Pass check.reportInfiniteRecursion took 68453ms
Pass check.reportInfiniteRepetition took 3ms
Pass check.reportIncorrectPlucking took 1ms
Pass transform.removeProxyRules took 5ms
Pass transform.inferenceMatchResult took 18ms
Pass generate.generateBytecode took 1685ms
Pass generate.generateJS took 475ms
Pass generate.generateParser took 33117ms !!!
✨  Done in 106.52s.

When I remove ts-pegjs plugin and just run Peggy 3, the performance is pretty close to Peggy 2:

Pass check.reportUndefinedRules took 16ms
Pass check.reportDuplicateRules took 2ms
Pass check.reportDuplicateLabels took 4ms
Pass check.reportInfiniteRecursion took 69878ms
Pass check.reportInfiniteRepetition took 3ms
Pass check.reportIncorrectPlucking took 2ms
Pass transform.removeProxyRules took 4ms
Pass transform.inferenceMatchResult took 18ms
Pass generate.generateBytecode took 1447ms
Pass generate.generateJS took 183ms
✨  Done in 73.97s.

While there are performance issues with Peggy itself (notably this reportInfiniteRecursion pass, which I have reported to peggyjs/peggy#457), the drop in performance of ts-pegjs is still very significant.

My initial guess is that this might be related to the changes to how ts-pegjs inferres type information. But really I have no clue.

nene commented

Update. Looks like my theory was correct. When I use skipTypeComputation: true, the typescript code generation time drops down to milliseconds:

Pass generate.generateBytecode took 1520ms
Pass generate.generateJS took 451ms
Pass generate.generateParser took 45ms

Given that I don't need this feature and I can easily disable it, this pretty much solves the issue for me. So feel free to close this issue.

But perhaps there is something that could be improved here.

Thanks for the report @nene
Indeed, we changed the way we calculate types, using a 3rd party library.
We will investigate if we can improve it.