-
Notifications
You must be signed in to change notification settings - Fork 67
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
Draft: Performance improvement around recursive definition of if statements #2756
Draft: Performance improvement around recursive definition of if statements #2756
Conversation
2f82f03
to
1d16be6
Compare
@QuantamHD, Let me work on adapting Surelog to this grammar, it is pretty involved, but first the new grammar is not complete, |
Locally on your machine, after changing the grammar, run: rm -rf build/bin/pkg to have fast turnaround. |
Could a similar method can be use to solve : #2035 ? |
@Thomasb81 It could help. It would be helpful to post what constructs you suspect are contributing to the expensive evaluation in black parrot. |
The file is attached in the issue, it is the regular if-else-if (Not the if-generate-else-if)
|
@alaindargelas I would stop working on adapting the grammars if you started. After I fixed the syntax issues I saw worse performance than master. I'll have to give this a bit more thought |
@QuantamHD, I'm not working on this. If you find a faster legal grammar, then I'll adapt Surelog to use that grammar. |
As @alaindargelas mentioned #2035 contain a testcase, that syntactically describe a cascade of "if else if" that is some how drawing the performance. At first glance it look very similar to the grammar part you address except it is not in a generate. Antlr literature discuss performance issue related to ambiguity but in this case tool is not reporting ambiguity. So any finding is very interesting. @alaindargelas Have you any method to only regress the grammar using existing testsuite but without having to update Surolg to grammar change but still having pre-processor wokring ? because realistic testcase often need preprocessor. I should admit that not having this capability at the time I try to contribute on #2035 has probably contribute to my give up. |
@Thomasb81, unfortunately, the fastest way is:
That runs in about 5 mins clock wall time on an 8 cores machine, including build time and whole regression. |
@QuantamHD, shall we close this? |
@alaindargelas I have another performance improvement suggestion around the generate ifs. In the current version of the grammar it relies on a recursive definition of if else. After profiling Surelog and ANTLR I've found that these recursive definitions kill performance. Each level of rule indirection that is calling one rule from another is a very expensive operation in ANTLR. The generate ifs in the Google test case have over 100,000 if else if branches which makes this file pretty slow.
In this PR I propose replacing the overly general grammar with a more tailored grammar that reduces the long rule chains that hurt performance. This will require a change in Surelog's ParseTree to AST code which I will take a look at, but if you can beat me to it @alaindargelas that would be ideal.
The grammar now relies on ()* which doesn't require adding a new context to the stack in ANTLR.
Test Case
Bad Profile
Old Version
New Version