性能问题我的语法和antlr4

时间:2013-04-10 13:02:04

标签: performance antlr4

我是使用antlr 4的新手,之前从未编写过语法。语法似乎对短样本工作正常,但我有一些较长的例子将在一夜之间完成。我正在使用TestRig和我的输入文件。我使用了JVisualVM并且大部分时间都在观察代码:

Org.antlr.v4.runtime.atn.ArrayPredictionContext.equals(Object) (89.8%)
Org.antlr.v4.runtime.atn.SingletonPredictionContext.equals(Object) (7.4%)
Org.antlr.v4.runtime.misc.DoubleKeyMap.put(Object,Object,Object) (1.8%)
Org.antlr.v4.runtime.misc.DoubleKeyMap.get(Object, Object) (0.9%)

问题似乎与以下格式的陈述量有关。

reservedWord  = quotedstring

这些问题发生在12到72之间

我已经给了jvm 2G的内存,并且使用的不到1G。堆增长和缩小,所以我不相信存在内存泄漏。

有关如何调试此类内容的任何建议吗?

我没有看到附加文件的方法,堆栈跟踪是422行,大多数重复1278和1325.我不懂TestRig所以我不知道它在做什么。如果我能找到它,将获得antlr-4.0-complete.jar的源代码。

at org.antlr.v4.runtime.atn.PredictionContext.hashCode(PredictionContext.java:121)  
at org.antlr.v4.runtime.atn.SingletonPredictionContext.equals(SingletonPredictionContext.java:97)   
at java.util.HashMap.getEntry(HashMap.java:349)     
at java.util.LinkedHashMap.get(LinkedHashMap.java:280)  
at org.antlr.v4.runtime.misc.DoubleKeyMap.get(DoubleKeyMap.java:60)     
at org.antlr.v4.runtime.atn.PredictionContext.mergeSingletons(PredictionContext.java:204)   
at org.antlr.v4.runtime.atn.PredictionContext.merge(PredictionContext.java:138)     
at org.antlr.v4.runtime.atn.ATNConfigSet.add(ATNConfigSet.java:354)     
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1293)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
<repeat a lot 1278 and 1325>

at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1325)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1325)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1261)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1325)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1261)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1325)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1325)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1261)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure_(ParserATNSimulator.java:1325)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closureCheckingStopState(ParserATNSimulator.java:1278)   
at org.antlr.v4.runtime.atn.ParserATNSimulator.closure(ParserATNSimulator.java:1216)    
at org.antlr.v4.runtime.atn.ParserATNSimulator.computeReachSet(ParserATNSimulator.java:988)     
at org.antlr.v4.runtime.atn.ParserATNSimulator.execATNWithFullContext(ParserATNSimulator.java:801)  
at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:701)     
at org.antlr.v4.runtime.atn.ParserATNSimulator.predictATN(ParserATNSimulator.java:389)  
at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:346)     
at ValidatingPolicyParser.showstatement(ValidatingPolicyParser.java:1023)   
at ValidatingPolicyParser.statement(ValidatingPolicyParser.java:685)    
at ValidatingPolicyParser.policy(ValidatingPolicyParser.java:246)   
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)    
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)    
at java.lang.reflect.Method.invoke(Method.java:597)     
at org.antlr.v4.runtime.misc.TestRig.process(TestRig.java:247)  
at org.antlr.v4.runtime.misc.TestRig.process(TestRig.java:209)  
at org.antlr.v4.runtime.misc.TestRig.main(TestRig.java:142)

我开始研究一种用于测试用例的修剪语法。这个练习确实帮助我找出了一些从语法中删除的奇怪之处。这解决了我的修剪语法的问题,但是当我恢复完整的语法时,性能问题又回来了。

对我来说,增加简单比较的出现次数非线性地增加处理时间似乎很奇怪。 “TOKEN =”SOMESTRING“或TOKEN =”SOMEOTHERSTING“'的几个实例处理相对较快,但如果我有75个比较处理时间变得过多。

我无法确定antlr4源是否在某处可用。很高兴通过代码来看看发生了什么。

猜猜我会重复这个过程,看看它产生了什么。

2 个答案:

答案 0 :(得分:1)

这些时间数据毫无用处。他们告诉你epsilon。

相反,只是打断它。你将在行动中抓住它。检查调用堆栈,如有必要,检查数据变量。如果您了解它在那个时间点正在做什么,您就会知道问题所在。

More than you ever wanted to know about that.

答案 1 :(得分:0)

我在语法中发现了问题。经过了大量的反复试验。我想知道是否在antlr4中使用了递归?