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

Add more optimizations #473

Merged
merged 16 commits into from
Apr 12, 2021
Merged

Conversation

SkiFire13
Copy link
Contributor

Adds a couple more optimizations:

  1. Converts (rule ~ rest) | rule to rule ~ rest?, avoiding trying to match rule twice. Same as the already existing factor but in the case the second expression is not Expr::Seq.

  2. Converts rule | (rule ~ rest) to rule since (rule ~ rest) will never match if rule didn't. Not sure if this should go in factorizer.rs but the pattern looked really similar.

  3. Converts (rule ~ rest)* ~ rule to rule ~ (rest ~ rule)*, avoiding matching the last rule twice, should have a big impact on issues like Improving slow Rockstar parser #453 and Very slow recursive pattern #463. Goes to a new file names lister.rs, not sure if the name is descriptive enough.

Actually there's a 4th optimization I thought of, converting (rule ~ rest)* ~ rule? to rule ~ (rest ~ rule)* ~ rest?, assuming rule is more expensive than rest but I don't think this can be determined if one of them contain an Expr::Ident. This would have the same effect of 3. on the relevant cases.

Copy link
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for taking time to write this! The change looks good, but I'd like to ask you to write some tests for this before merging.

Copy link
Contributor

@dragostis dragostis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat! Again, thanks a lot for this. 👍

bors r+

bors bot added a commit that referenced this pull request Sep 23, 2020
473: Add more optimizations r=dragostis a=SkiFire13

Adds a couple more optimizations:

1. Converts `(rule ~ rest) | rule` to `rule ~ rest?`, avoiding trying to match `rule` twice. Same as the already existing `factor` but in the case the second expression is not `Expr::Seq`.

2. Converts `rule | (rule ~ rest)` to `rule` since `(rule ~ rest)` will never match if `rule` didn't. Not sure if this should go in `factorizer.rs` but the pattern looked really similar.

3. Converts `(rule ~ rest)* ~ rule` to `rule ~ (rest ~ rule)*`, avoiding matching the last `rule` twice, should have a big impact on issues like #453 and #463. Goes to a new file names `lister.rs`, not sure if the name is descriptive enough.

Actually there's a 4th optimization I thought of, converting `(rule ~ rest)* ~ rule?` to `rule ~ (rest ~ rule)* ~ rest?`, assuming `rule` is more expensive than `rest` but I don't think this can be determined if one of them contain an `Expr::Ident`. This would have the same effect of 3. on the relevant cases.

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
@bors
Copy link
Contributor

bors bot commented Sep 23, 2020

Timed out.

bors bot added a commit that referenced this pull request Oct 31, 2020
480: Fix build after PR #454 r=CAD97 a=SkiFire13

PR #454 broke the build by adding a doctest that doesn't compile, in particular it gave the following error:

```
failures:

---- src/error.rs - error::ErrorVariant<R>::message (line 445) stdout ----
error[E0282]: type annotations needed for `pest::error::ErrorVariant<R>`
 --> src/error.rs:447:15
  |
5 | let variant = ErrorVariant::CustomError {
  |     -------   ^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type for type parameter `R` declared on the enum `ErrorVariant`
  |     |
  |     consider giving `variant` the explicit type `pest::error::ErrorVariant<R>`, where the type parameter `R` is specified

error: aborting due to previous error

For more information about this error, try `rustc --explain E0282`.
Couldn't compile the test.

failures:
    src/error.rs - error::ErrorVariant<R>::message (line 445)

test result: FAILED. 59 passed; 1 failed; 2 ignored; 0 measured; 0 filtered out
```

This error made PRs #470's and #473's bors build fail. After this PR is merged bors should be re-run for them.

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
@CAD97
Copy link
Contributor

CAD97 commented Oct 31, 2020

I'll re-r this once CI is fixed (#483), but I unfortunately really don't have time to sort through the new style warnings and apply/ignore them right now. I already spent too much time on this, grad school is really eating all of my time

Copy link
Contributor

@CAD97 CAD97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the merge issue and I'll merge this.

@SkiFire13 SkiFire13 requested a review from CAD97 November 1, 2020 11:06
Copy link
Contributor

@CAD97 CAD97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bors r=dragostis

Will manually merge when CI passes

bors bot added a commit that referenced this pull request Nov 1, 2020
473: Add more optimizations r=dragostis a=SkiFire13

Adds a couple more optimizations:

1. Converts `(rule ~ rest) | rule` to `rule ~ rest?`, avoiding trying to match `rule` twice. Same as the already existing `factor` but in the case the second expression is not `Expr::Seq`.

2. Converts `rule | (rule ~ rest)` to `rule` since `(rule ~ rest)` will never match if `rule` didn't. Not sure if this should go in `factorizer.rs` but the pattern looked really similar.

3. Converts `(rule ~ rest)* ~ rule` to `rule ~ (rest ~ rule)*`, avoiding matching the last `rule` twice, should have a big impact on issues like #453 and #463. Goes to a new file names `lister.rs`, not sure if the name is descriptive enough.

Actually there's a 4th optimization I thought of, converting `(rule ~ rest)* ~ rule?` to `rule ~ (rest ~ rule)* ~ rest?`, assuming `rule` is more expensive than `rest` but I don't think this can be determined if one of them contain an `Expr::Ident`. This would have the same effect of 3. on the relevant cases.

Co-authored-by: Giacomo Stevanato <giaco.stevanato@gmail.com>
@bors
Copy link
Contributor

bors bot commented Nov 1, 2020

Timed out.

@MarinPostma
Copy link
Contributor

bors merge

@bors
Copy link
Contributor

bors bot commented Apr 12, 2021

@bors bors bot merged commit 7c5ea59 into pest-parser:master Apr 12, 2021
@SkiFire13 SkiFire13 deleted the more-optimizations branch April 12, 2021 10:29
@f0i f0i mentioned this pull request Jun 21, 2022
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

Successfully merging this pull request may close these issues.

4 participants