rhaiscript / rhai

Rhai - An embedded scripting language for Rust.
https://crates.io/crates/rhai
Apache License 2.0
3.63k stars 174 forks source link

Pre-compile scripts? #865

Closed VinnyVicious closed 3 weeks ago

VinnyVicious commented 3 months ago

Would it be possible to pre-compile rhai scripts used in an application and bundle them with the application? The reason I ask is due to the fact that performance is not great (compared to our current implementation with C++ and LuaJIT), but there are clear advantages in our project by moving to Rust/Rhai. If pre-compiling was a possibility, then I'm sure speed would be much better.

schungx commented 3 months ago

That would require serializing the AST into some format (perhaps binary). However, based on my previous benchmarks, it doesn't seem to be faster deserializing an AST vs just compiling the script again. In fact, compiling a script into AST appears to be faster than deserializing a pre-generated AST from binary format.

If scripts compilation need only be done once, I wonder what would be the problem with your performance issues?

schungx commented 3 months ago

In fact, you can use Rust with LuaJIT and then retain all your existing scripts. There are Rust bindings for LuaJIT, I believe.

Why not go that route?

VinnyVicious commented 3 months ago

Rhai allows me to easily build to tons of platforms, including musl. LuaJIT is kind of prohibitive. :(

schungx commented 3 months ago

Rhai allows me to easily build to tons of platforms, including musl. LuaJIT is kind of prohibitive. :(

OK... that makes sense.

So what aspects of Rhai do you find slower than you wish?

VinnyVicious commented 3 months ago

Haven't got that deep down yet, it was a very native comparison between separate builds doing the same game logic. Once I have useful and actionable information, I'll share it for sure.

Thanks for creating rhai! :)

schungx commented 3 months ago

Thanks for creating rhai! :)

Well I didn't create Rhai... it was originally created by JT. I merely picked up maintenance of it.

schungx commented 3 weeks ago

Closing this for now. Feel free to reopen if there are further issues.