antlr / grammars-v4

Grammars written for ANTLR v4; expectation that the grammars are free of actions.
MIT License
10.15k stars 3.7k forks source link

golang parser is slow #1596

Open zzrrxx opened 4 years ago

zzrrxx commented 4 years ago

I tried to parse a 600 lines Golang code with the grammar file GoParser.g4 and GoLexer.g4, it almost needs about 20s with the Swift release build (80s for the debug build). I used Antlr4 4.7.2.

During running my parse app, a lot of reportAmbiguity and reportAttemptingFullContext error are reported.

My question is is there any tips or tricks to make it run faster? I tried the two-step parsing, it doesn't work for me. Any help? Thanks

KvanTTT commented 4 years ago

I tried to parse a 600 lines Golang code with the grammar file GoParser.g4 and GoLexer.g4, it almost needs about 20s with the Swift release build (80s for the debug build). I used Antlr4 4.7.2.

It sounds awful. I think there are performance problems with Swift runtime. Have you tried Java of C# ones?

Also, I suppose you implemented GoParserBase.swift for Swift runtime? There are only C#, Java and Go files in the repository.

zzrrxx commented 4 years ago

Thank you for your prompt reply.

I tried Java, it takes about 3s to parse the same Golang file.

Also, I suppose you implemented GoParserBase.swift for Swift runtime?

Yes, I write GoParseBase.swift according to the provided GoParserBase.java.

KvanTTT commented 4 years ago

Anyway, it's too much time for such a small file.

zzrrxx commented 4 years ago

So will you fix it in the near future?

KvanTTT commented 4 years ago

No, maybe @ewanmellor (Swift target maintainer) can help. Could you please attach your Go file that's parsed too slowly?

zzrrxx commented 4 years ago

https://github.com/zzrrxx/paho.golang/blob/master/paho/client.go

Thanks!

KvanTTT commented 4 years ago

The parsing file of such a file is less than 1 sec on my machine (Core i5, 3.5 GHz, 16 Gb) on C# runtime.

zzrrxx commented 4 years ago

I use swift and use the Antlr4 in my ios app, could you please have a try?

Just as I mentioned before, Java version takes about 3 second in IntelliJ. So I think only Swift runtime’s performance is poor.

Thanks

在 2020年1月11日,下午11:26,Ivan Kochurkin notifications@github.com 写道:

 The parsing file of such a file is less than 1 sec on my machine (Core i5, 3.5 GHz, 16 Gb) on C# runtime.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

KvanTTT commented 4 years ago

Unfortunately no, I don't have installed macOS. Java runtime also has better performance, maybe there are IntelliJ freezes.

teverett commented 4 years ago

I have MacOs, but will need some instructions.

zzrrxx commented 4 years ago

@teverett Please keep me updated if you make any progress. Also, let me know if I can do anything for you.

bbbiggest commented 3 years ago

I parsed a 663 lines Golang file, it needs about 120s. And when I parsed a 83 lines Golang file in examples/structs.go, it also needs about 20s with the Python3.8. It's too slow.

I used Antlr4 4.9.2 in Windows10. And I write GoParseBase.py according to the provided GoParserBase.go. Is this a problem with the Go language, or the file I wrote is not good enough? By the way, it's fast when parsing Java.