-
Notifications
You must be signed in to change notification settings - Fork 807
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
Algorithmic optimizations on math.ease functions #2198
base: master
Are you sure you want to change the base?
Conversation
I'd like to see the benchmarks you have performed. I am having trouble seeing a consistent improvement, or any at all using the example from wiki:
Sometimes the proposed changes are slower than the current code in these results. |
Sure, I will post the benchmarking code tomorrow. But it was kinda similar to yours, @robotboy655, so I'm not sure on why my results were drastically different... In the meantime, here are my (low-end) specs on which I performed my test: :)
What version of Lua does Garry's Mod uses ? 5.3 ? 5.4 ? |
GMod uses LuaJIT, which is Lua 5.1. I am testing on a fairly good machine with a Ryzen 5900x, on Windows 10. |
Runtime performance between PUC Lua 5.1 (or really any version of PUC Lua) and LuaJIT is wildly different, especially on the math side of things since in LuaJIT most of that stuff (including pow) gets optimized into machine instructions and even when the relevant code that's being run doesn't make it through the JIT most of the math operations themselves are implemented in assembly rather then C. Any benchmarking that's done NEEDS to be done with/in LuaJIT or the results won't matter, better yet benchmarking should probably be done inside GMod itself as done in a prior comment on this PR if possible. @RubisetCie |
OK, here are the scripts I made to do my benchmarking:
It may be naive, but I did another test this morning using LuaJit, and the results were like even more drastic... especially for InCubic, where I get an improvement so big I suspect there may be an error... so I'm curious about your analysis. :) |
This is true. That could explain the lack of improvements if the benchmarks are refuted.
LuaJit is done, and shows improvements. I'll test in GMod right now. |
After doing a bunch of benchmarking and testing and digging (I ended up testing 12 different compiles of LuaJIT) I have found out and concluded that this behavior is LuaJIT version dependent. If GMod ever updates it's copy of LuaJIT to a modern version (hopefully it will one day) then this pull request would actually be useful if the performance of LuaJIT POW benchmark results.rar.zip related LuaJIT commits/issues: |
Thank you for this deep analysis, @goodusername123 :) So, I guess it's better to merge my PR, but I'm bothered by the current Garry's Mod benchmarks, which showed the new version being sometimes slower than the old one... even if there's a confounding factor, I'm troubled. :| |
I've noticed You've increased MAX_MAP_BRUSHES from 16384 to 65535, does this mean really big maps is possible? |
Good day.
Because my addons rely heavily on
math.ease
functions (which is an awesome addition for the glua, btw), I took the responsibility to optimize some of its expressions.Mainly, it is about converting the
^
operator to a succession of multiplications*
; it is faster because exponentiation in Lua relies on thepow
C function, which is too much overhead for simple squaring, cubing, etc.So,
x ^ 2
becomesx * x
, and so on...