intellij-plugin-v4 icon indicating copy to clipboard operation
intellij-plugin-v4 copied to clipboard

Possible memory leak with the ANTLR Preview pane.

Open KitsuneAlex opened this issue 3 years ago • 11 comments

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 avatar May 15 '22 16:05 KitsuneAlex

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

KitsuneAlex avatar May 15 '22 16:05 KitsuneAlex

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 avatar May 15 '22 16:05 parrt

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

parrt avatar May 15 '22 16:05 parrt

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

parrt avatar May 15 '22 17:05 parrt

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.

KitsuneAlex avatar May 15 '22 17:05 KitsuneAlex

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

parrt avatar May 15 '22 17:05 parrt

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

parrt avatar May 15 '22 17:05 parrt

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

parrt avatar May 15 '22 18:05 parrt

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

parrt avatar May 15 '22 18:05 parrt

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 avatar May 15 '22 18:05 parrt

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

parrt avatar May 15 '22 18:05 parrt