antlr / intellij-plugin-v4

An IntelliJ plugin for ANTLR v4
https://plugins.jetbrains.com/plugin/7358-antlr-v4
BSD 3-Clause "New" or "Revised" License
467 stars 105 forks source link

Possible memory leak with the ANTLR Preview pane. #553

Open KitsuneAlex opened 2 years ago

KitsuneAlex commented 2 years ago

I've been using this plugin to work on my language since it's validation and visualization features are very very nice.

Since my parser has reached a certain size (~1600 lines), using the preview pane has become quite literally impossible. It takes forever to rebuild what i suspect to be a cached pre-built parser for the current grammar, since i also suspect said rebuild being initiated on every key-input event in the editor.. Not sure tho.

I did a little test today and found out that while using the preview pane, my JVM heap is completely used up. I increased the maximum heap size for the IDE to 16GB, which was also used up. I repeated the increasing until i couldn't spare any more memory on my system, which happened to be the 56GB mark (i have 64GB installed currently).

After reaching 56GB, the IDE just crashed, and i have no hs_err* file, nor another form of crash report and i'm kind of lost here, since i am not much into IDEA-related APIs (yet).

OS: PopOS 22.04 LTS (Kernel 5.17.5-76051705-generic) JVM: JetBrains Runtime 11.0.14.1+1-b2043.45 (amd64) IDE: IntelliJ IDEA Ultimate 2022.1.1 (Build 221.5591.52) Plugin Version: 1.18

KitsuneAlex commented 2 years ago

The grammar i am working on that is causing these problems can be found here. Keep in mind that it's still work in progress and it's gonna be subject to lot's of optimizations once it's feature complete :D

parrt commented 2 years ago

Hi. Yup. just fixed it!! check this one out https://github.com/antlr/intellij-plugin-v4/issues/546 can you try to install that build? Almost ready for release.

https://github.com/antlr/intellij-plugin-v4/files/8691177/antlr-intellij-plugin-v4-1.19-SNAPSHOT.zip

parrt commented 2 years ago

(uninstall antlr plugin then "install from disk" that zip)

parrt commented 2 years ago

The first thing to check is whether or not your partner works for empty or trivial input even from the command line. I suspect there's an infinite Loop in your grammar. Make sure to check for any warning messages from antlr about empty rules

KitsuneAlex commented 2 years ago

The memory "leak" even occurs when there's no input to parse in the preview pane, that's the odd thing. But i forked the plugin and i'm gonna try to cut down memory usage a bit, already saw a few things.

parrt commented 2 years ago

so no warnings in antlr console? Try hitting the red square parse cancel button

parrt commented 2 years ago

Those mem objs are all from parsing gone nuts...not a leak per se.

parrt commented 2 years ago

Yeah, something is hosed with parsing of that grammar itself. Seems like a bug in plugin

parrt commented 2 years ago

Something in the grammar is causing static grammar analysis in plugin to go nuts but NOT from command line.

parrt commented 2 years ago

Wow. it takes ANTLR 6s on my fast box to process your parser .g4 file!!!! I have a trivial main() that exhibits...it's antlr issue not plugin :) Confirmed command line is same time.

parrt commented 2 years ago

@KitsuneAlex I moved issue to antlr, leaving this open... https://github.com/antlr/antlr4/issues/3711