Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offline parser generation? #193

Open
jeroenvandijk opened this issue Apr 10, 2019 · 3 comments
Open

Offline parser generation? #193

jeroenvandijk opened this issue Apr 10, 2019 · 3 comments

Comments

@jeroenvandijk
Copy link

Maybe this is a completely ignorant question, apologies upfront. I'm really thankful for what Instaparse is already.

Having said that, would it be possible to generate the parser offline and safe it as Clojure code? And would this be a good fit for this project?

The benefits would be:

  • Minimal dependencies
  • Faster boot time for scripts (see below)
clojure -Sdeps '{:deps {instaparse {:mvn/version "1.4.10"}}}'
Clojure 1.10.0
user=> (time (eval '(do (require '[instaparse.core :as insta])
                 (insta/parser "S = AB*
                         AB = A B
                         A = 'a'+
                         B = 'b'+"))))
"Elapsed time: 1416.731897 msecs"
S = AB*
AB = A B
A = "a"+
B = "b"+

(When I precompile the parser as a jar and def it, this doesn't make a difference.)

@jeroenvandijk
Copy link
Author

Sorry it's mostly the require that takes a long time

clojure -Sdeps '{:deps {instaparse {:mvn/version "1.4.10"}}}'
Clojure 1.10.0
user=> (time (require '[instaparse.core :as insta]))
"Elapsed time: 1320.385786 msecs"

But the reasoning still applies I believe

@Engelberg
Copy link
Owner

defparser macro addresses this to some extent, although more relevant to Clojurescript than Clojure. You might want to explore whether that macro can help on Clojure with precompilation; I'm not certain whether it does. If that doesn't help, some users have reported success in building Graal based images with instaparse, and say that it gives very fast startup time. See https://github.com/alexei-matveev/instaparse-demo for a detailed example.

@jeroenvandijk
Copy link
Author

Thanks @Engelberg for pointing me to the GraalVM and Instaparse work.

I've just tested it and it seems not to be true anymore (alexei-matveev/instaparse-demo#2). Maybe this is due to GraalVm changes or Clojure changes (from 1.9 and above compilation get's more difficult with clojure.spec).

I'll look at the defparser macro. Clojurescript seems to have an offline version of the parser indeed.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants