rrevenantt / antlr4rust

ANTLR4 parser generator runtime for Rust programming laguage
Other
398 stars 70 forks source link

Slow parsing performance #49

Closed mlynch closed 2 years ago

mlynch commented 2 years ago

I'm using antlr4rust to build a Kotlin parser. I was able to successfully generate the parser using the v0.3 branch of this library and I can now parse Kotlin programs. However, I'm noticing that parsing is very slow. Parsing a small Kotlin script takes over two seconds. One reason I wanted to write this parser in Rust was for performance, but this feels on par with my JVM-based parsers I've had in the past and those weren't fast enough for my needs.

Is there anything I might be doing wrong? Here's my code so far: https://github.com/ionic-team/trapeze/tree/main/packages/parser

In the meantime I'm going to try the C++ runtime and compare parsing the same program. Will follow up once I have results.

rrevenantt commented 2 years ago

Hmm..., you seem to test that in debug mode, on my relatively old laptop with i5-7200U it takes 2.47s in debug and 186.86ms in release.

Moreover you have benchmarked only first invocation of the parser which is supposed to be noticeably slower because it has to cache most of the internal DFA which will be reused by subsequent runs (those take 40ms for me)

mlynch commented 2 years ago

Ah, that makes sense. When I test in release mode it's much faster (266ms). I'm pretty new to rust so I didn't think the delta between debug and release would be so big. In the meantime I had gotten the C++ version working and the Rust version is considerably faster. At full optimization (as far as I can tell), I'm getting > 0.8s to parse: https://github.com/mlynch/kotlin-parse-test-cpp

Closing as this is not an issue, thanks for the response.