-
Notifications
You must be signed in to change notification settings - Fork 55
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
The performance is not particularly great compared to Lua #163
Comments
Related issue: #140 |
@skejeton Your Lua example:
can be even 10x faster than Umka if you declare Sad for Umka. |
Update W.R.T. performance. Here I'm using Lua 5.4 downloaded from official website vs Umka from the current main branch compiled with build_windows_msvc.bat on VS 2022. Please note that the performance differences may be a bit weird because last time when I ran it, I ran it on a Linux machine, not Windows. Nonetheless: Testsfn main() {
x := 0.0
for i := 0.0; i <= 10000000.0; i += 1 {
x += i
x /= 2.0
}
printf("%f\n", x);
} = 1.121s x = 0
for i=0,10000000 do
x = x + i
x = x / 2
end
print(x) = 0.423s fn fib(x: int): int {
if x < 2 {
return x
}
return fib(x-1) + fib(x-2)
}
fn main() {
printf("%d\n", fib(40))
} = 21.338s function fib(x)
if x < 2 then
return x
else
return fib(x-1) + fib(x-2)
end
end
print(fib(40)) = 11.116s type (
StringMod = interface {
f(s: str): str
}
TypeA = struct {}
TypeB = struct {}
)
fn (t: ^TypeA) f(s: str): str {
return s + "a"
}
fn (t: ^TypeB) f(s: str): str {
return "b"
}
fn apply(iface: StringMod, n: int): str {
s := ""
for i := 0; i <= n; i++ {
s = iface.f(s)
}
return s
}
fn main() {
a := TypeA{}
b := TypeB{}
apply(a, 100000)
apply(b, 100000)
} = 2.611s function apply(interface, n)
s = ''
for i=0,n do
s = interface.f(s)
end
return s
end
a = { f = function(s) return s .. 'a' end }
b = { f = function(s) return 'b' end }
apply(a, 100000)
apply(b, 100000) = 0.487s fn apply(f: fn (s: str): str, n: int): str {
s := ""
for i := 0; i <= n; i++ {
s = f(s)
}
return s
}
fn main() {
apply(fn (s: str): str { return s + "a"; }, 100000)
apply(fn (s: str): str { return "b" }, 100000)
} = 2.532s function apply(f, n)
s = ''
for i=0,n do
s = f(s)
end
return s
end
apply(function(s) return s .. 'a' end, 100000)
apply(function(s) return 'b' end, 100000) = 0.462s RemarksFor some reason interfaces function significantly slowly, than before. I'm not sure whether it's because of an OS change or Umka change, or some other factor. Best way to verify is to test on Jun 17 version. |
For this script
The body of the while loop has 25 instructions. For this script
The body of the while loop has 10 instructions.
Even if I think this is a problem in all implementations that execute bytecode (Umka, Puc/Lua, CPython, Perl, Quickjs, etc). One simply can not afford to write while loops in them, but instead must rely on built-in functions to the the heavy lifting/looping. |
Perhaps we could benefit from adding more complex instructions? For example a variant of binary, which works on the top two elements of the stack. Would that be worth it? |
@luauser32167 You're right, the Umka virtual machine is not optimized enough. Please notice, however, that a one-to-one comparison between Umka and Lua 5 bytecode is hardly possible, since Umka is stack-based and Lua 5 is register-based. @marekmaskarinec I sometimes think of having a single complex instruction for a |
Take something like this
versus this
First is umka, second is lua. On my computer at least, umka is about 3x slower. Which is a shame because it has potential to be much faster than lua. I usually don't pay attention to the speed of scripting languages, since it's almost always not the issue, however since I'm writing almost the entire game in umka, the speed matters, and it shows: Most of the "self" execution time is spent in vmRun.
The above isn't a perfect benchmark, so here's few more (these benchmarks mostly tackle umka's "raw" speed, e.g. crunching speed):
20 seconds
vs
10 seconds
(lua about 2x faster)
(interface version) 600ms
(function pointer version) 900ms
("interface" version) 400ms.
(function pointer version) 566ms
There's more I can show. But I just think there's room for improvement when it comes to performance. I've tried to re-implement umka with focus of VM performance, but the project is nowhere near as complete as umka. While it's faster than Lua in general, I don't think it's fair to compare it with umka yet. (https://github.com/skejeton/elka), It's pretty much abandoned//
Either way, good luck. And if something, just ask me. I'll be glad to respond and/or help.
Originally posted by @skejeton in marekmaskarinec/tophat#30 (comment)
The text was updated successfully, but these errors were encountered: