Stream: cranelift

Topic: JIT/AOT compilation of DSL


view this post on Zulip Lucas (Apr 14 2022 at 08:00):

Hello! Indulge me for a moment if you will. Completely new to cranelift but decent at rust. I have a DSL that is run in a hot loop that is essentially this:

if a > b:
  "apple"
else if c == 23 && name == "jinxit":
  "banana"
else if you_get.contains("the idea"):
  "lemon"
...

The input DSL is only known at runtime so I would like to compile this (can be "slow") and run it (must be fast). I'm getting a bit lost in the terminology though, what parts of cranelift should I be looking at? JIT to me like it would run slower than AOT, but maybe that's not accurate?

view this post on Zulip bjorn3 (Apr 14 2022 at 12:38):

Cranelift is optimized for JIT compilation. It is missing a lot of optimizations for example LLVM has. This means that it can compile fast, but the code runs slower. If you want your code to run as fast as possible you should probably try LLVM. LLVM has a JIT engine too. It just compiles slower than Cranelift.

view this post on Zulip bjorn3 (Apr 14 2022 at 12:40):

JITted code doesn't necessarily run slower than AOT compiled code. In fact in case of a JIT some overhead may be avoided in certain cases. The main difference between the two is if you compile it first and then run it at a later time (AOT, ahead of time) or compile it just before you run it (JIT, just in time).


Last updated: Nov 22 2024 at 16:03 UTC