Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nene opened this issue Jan 2, 2024 · 2 comments
Closed

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

nene opened this issue Jan 2, 2024 · 2 comments

Comments

@nene
Copy link

nene commented Jan 2, 2024

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
Copy link
Author

nene commented Jan 2, 2024

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.

@pjmolina
Copy link
Contributor

pjmolina commented Jan 2, 2024

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.

@pjmolina pjmolina closed this as completed Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants