Parser created under javascript runtime has performance issue

44 views
Skip to first unread message

Wenhou

unread,
Sep 5, 2018, 2:39:06 PM9/5/18
to antlr-discussion
Hi,

I'm a antlr4 learner and I tried to create a SQL parser under the javascript runtime. From my testing I found it very slow when dealing with complex queries. For example, parsing a SQL query would take 15 seconds while on Spark it almost immediately returned (I believe Spark is using the same grammar file and same way to parse a SQL query to create the logical plan while the only difference is they're built under java runtime).

After profiling my entire program, I found that it spent most of the time on .toString() function calls. Those calls are made in this line

var existing = visited[context] || null;

which is from getCachedPredictionContext() in PredictionContext.js. The reason is that javascript object only supports simple types, like string, as keys. If it's an object type then it will be casted using .toString() automatically. This is not an issue under the java runtime though, which seems to make a lot of sense for what we've observed.

I was thinking a possible solution might be to replace Object with Map so that we can get rid of the .toString(). But considering constructing Map is slower than Object, I'm not sure how it can improve the overall performance.

Do we have any suggestion on how we can solve this performance issue? Please also feel free to correct me if there is anything wrong with my approach above.

Any comment will be appreciated!
Reply all
Reply to author
Forward
0 new messages