Issue #10934: OutOfMemory Error following ANTLR4 upgrade#10999
Conversation
72bfc86 to
8c03584
Compare
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
8c03584 to
44c1631
Compare
44c1631 to
10a2890
Compare
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
|
Github, generate report |
|
Report generation job failed on phase "make_report", step "Generate report". |
This will never run to completion in github action (when generating diff report), because we are running this PR branch (which will allow execution of We know that report generation on newer openjdks with lower memory will complete in github action once this is merged because of https://github.com/checkstyle/checkstyle/runs/4422848467?check_suite_focus=true I will try to generate report in single mode. |
|
Github, generate report |
|
Single report generation is successful, so once we fix #10934, we will be able to complete checkstyle/contribution#527 by using adding the openjdk project in this PR description. We will also be able to add openjdk16 project to https://github.com/checkstyle/contribution/blob/master/checkstyle-tester/projects-to-test-on-for-github-action.properties for github action diff report generation. |
Can you run this locally and give the regression more memory? |
| * @param input the token stream to parse | ||
| * @param dummyArg dummy argument | ||
| */ | ||
| public JavaLanguageParser(TokenStream input, boolean dummyArg) { |
There was a problem hiding this comment.
Do we need to make similar changes to the Javadoc? Why?
There was a problem hiding this comment.
Do we need to make similar changes to the Javadoc?
Assuming you mean Javadoc grammar here, we certainly could if we needed to; since this issue was reported for 9.X update, I only targeted the Java grammar.
There was a problem hiding this comment.
Assuming you mean Javadoc grammar
Yes.
if we needed to
This is what my question is connected to. If we need further analysis on if Javadoc grammar needs this, then lets create an issue for it it. If there is no harm to adding it just to be sure we don't have to worry about it later, then I am fine with doing it too.
There was a problem hiding this comment.
After thinking on this, I believe that this may hurt Javadoc grammar performance more than helping it. Consider post at http://roman-ivanov.blogspot.com/2016/02/performance-problem-while-using-checks.html, where we can see that Javadoc parsing slows Checkstyle execution significantly. In this case, DFA clearing will likely slow parsing even more. I can open an issue if you would like, but the Javadoc grammar has much more severe issues than memory usage; I would address them before employing any memory hacks.
There was a problem hiding this comment.
I am ok if you are since you know this stuff more. I just want to make sure it was looked at.
There was a problem hiding this comment.
@nmancus1 , please update issue description (if we have issue to this) to look at upadate like in this PR to possibly improve javadoc speed.
update of javadoc is not in scope of this PR.
|
Just run into this issue after upgrading checkstyle in a big maven project from 8.x to 9.2.1. I tried @nmancus1 issue-10934-3 branch and the build passed without hitting an OOM as with checkstyle 8.x. Also didn't notice any regression of the build time. So I think, the issue's fixed with the change in that branch. |
7b08dde to
5a3c6c7
Compare
|
GitHub , rebase |
68458bb to
890a83e
Compare
| public JavaLanguageParser(TokenStream input, boolean dummyArg) { | ||
| super(input); | ||
| _interp = new ParserATNSimulator(this, _ATN , _decisionToDFA, _sharedContextCache); | ||
| if (++fileCounter % 500 == 0) { |
There was a problem hiding this comment.
@nmancus1 I'm ok with this constant, but what if we turn this into a parameter? Instead the dummyArg there can be dfaLimit or something like that. It is even possible to add a property to the TreeWalker to make it configurable by the user.
|
Better to avoid extension of Treewalker properties. |
88ac134 to
a9b5f88
Compare
70c2c54 to
7d567c6
Compare
7d567c6 to
de1a867
Compare
|
Let's merge as CI pass |

Closes #10934 .
Report from investigation of issue here: https://github.com/nmancus1/checkstyle-antlr4-memory-report
Further investigation has led me to the current implementation, and has disproven some results of my previous investigation. In order to keep memory usage down, clearing the lexer DFA is not as important as my original research concluded. Also, I have found that it is not critical to instantiate a new
PredictionContextCacheas some suggested in the ANTLR issues that I read through.The root of the problem is that ANTLR DFA states are basically stored in an unbounded cache; as long as we keep finding syntax that is different than what has been previously parsed, the number of DFA states (and heap size) continues to grow without bound as we parse more files. The suggested approach of clearing the DFA states upon every parsing operation (every file) had much too high of a time performance cost.
The current implementation (clearing the DFA states every 500 files) gets us to a very good state performance wise; memory consumption is reasonable (stays within all specified JVM heap sizes), and parsing speed is nearly back to ANTLR2 times.
You can see the history of all
no-exception-openjdk16task execution here (most relevant real life metric of performance of changes in this PR):https://github.com/checkstyle/checkstyle/actions/workflows/no-exception-workflow.yml?query=branch%3Aissue-10934-3
Note that file counter dfa clearing was added 12/29; you can see that most subsequent runs are equal to, or less than 30 minutes.
Some metrics from CI:
CI tasks always have some variance on run times, but averaging out the master run times of these tasks gives us a good idea of how long certain executions should take.
Diff Regression projects: https://gist.githubusercontent.com/nmancus1/179fb374eb149c629322508baadc6ce1/raw/8f926d3450ba23172df94f39fd6901a355550d7a/projects.properties
New module config: https://gist.githubusercontent.com/nmancus1/ead52600003f218fb17823bc59ea596f/raw/a6cd0780e9f6e13296380c8328f7c064baa6c95e/config.xml