rbartlensky / Lua-interpreter

A Lua interpreter in Rust
5 stars 2 forks source link

I think add up result from benchmark would be nice ! #25

Open thetrung opened 2 years ago

thetrung commented 2 years ago

I test with this Luavm, Lua 5.4 and LuaJIT :

        ./run.py -b ./benchmarks/fib.lua -n 2

        Running luavm on ./benchmarks/fib.lua
        Mean: 1.837, Std.Dev: 0.046, Margin of error: 0.08378932514348113

        Running lua on ./benchmarks/fib.lua
        Mean: 0.073, Std.Dev: 0.005, Margin of error: 0.009107535341682732

        Running luajit on ./benchmarks/fib.lua
        Mean: 0.011, Std.Dev: 0.0, Margin of error: 0.0

        &$1.8370 \scriptstyle \pm \small{0.0838}$ &$0.0730 \scriptstyle \pm \small{0.0091}$ &$0.0110 \scriptstyle \pm \small{0.0000}$ \\

I actually feel your implementation was pretty nice, but don't know why it's 25X slower than Lua5.4 👍 Does that mean Rust is slower than pure C ? No ?

Anyway, I'm happy to found you guys's work while thinking about a VM in Rust.

rbartlensky commented 2 years ago

Hey @thetrung, I am flattered by your kind words!

There's many reasons why the implementation is much slower, but the main points are:

There's also this post about GCs and why they're tricky to implement in Rust that is worth looking at.

Since this was my final year project, I also have a dissertation about it (together with a section on performance). If you want I can open-source it, and you can have a look around for a more complete answer to your question.

[1] Lua5.4 might've added even more interesting optimisations, but I am not aware of them

thetrung commented 2 years ago

According to the post, Rust imutable nature made it hard for GC to operate properly, but what if we don't use GC but similar borrow-checker for Lua ?

rbartlensky commented 2 years ago

Lua is a GC'd language, so you have to implement a GC in your VM.

For the last bit of your question, I'm not sure I follow what you're asking.

thetrung commented 2 years ago

It's just my thinking, like "what if" we can make a Lua, without GC, but borrow-checker instead.

Anyway, thanks for answering my question. If you guys have a discord a group to discuss more on this compiler thing then it would be cool.

rbartlensky commented 2 years ago

Sorry, but this isn't an active project. If you have any specific questions, feel free to drop them in here!