-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Implement vector and node conversion in Lua #12609
Conversation
Some suggestions:
|
|
c279dc4
to
4cb0851
Compare
I don't see the point here. You're trading two |
I thought using the Lua stack less could maybe result in a performance benefit. But those suggestions weren't based on any real knowledge. They were meant as something that one could try out. I should've made that more clear, sorry. |
This is to let minetest#12609 work on the client.
c14fb5f
to
2fdc447
Compare
@TurkeyMcMac please rebase |
This is to let minetest#12609 work on the client.
0f6682c
to
6b229d0
Compare
6b229d0
to
b98b62c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks fine otherwise.
Haven't tested.
b98b62c
to
9bf9af7
Compare
9bf9af7
to
13bbe0c
Compare
The only thing I'm wondering about is whether we should have a short snippet in C++ that checks that |
684a62e
to
cd246a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works, measured a 30% improvement to bench_get_node
50f492b
to
1ac1fa1
Compare
This makes error messages quite less friendly: minetest/bin/../builtin/common/item_s.lua:229: bad argument #1 to '__index' (string expected, got nil) happens when you pass a string, empty table or other stuff to a function expecting a node |
Co-authored-by: sfan5 <[email protected]>
As @paradust7 found and reported in #12438, constructing Lua strings and tables from C++ is slow. Looking at the code of PUC Lua and LuaJIT, this slowness affects calls such as
lua_getfield
, which have to construct/hash strings every time they are called. On the other hand, LuaJIT can optimize regular field accesses by storing strings and their hashes inline etc. This PR reimplements the functions for pushing and reading nodes and vectors using Lua. Unlike #12438, it does not touch specific API functions. Therefore, it will have wider reaching effects, but will probably not give as much improvement forget_node
in particular. I have found that it indeed provides significant improvement.To do
This PR is Ready for Review.
How to test
Run the unit tests, and maybe some other mods.
Benchmarks
First apply this patch for some extra benchmarking commands:
Then run these benchmarks:
/bench_bulk_set_node
: This benchmarks the reading of nodes and vectors. Theset_node
loop tests both in equal proportion, whilebulk_set_node
mainly just benchmarks reading vectors. I have noticed a 10-15% decrease in runtime of theset_node
loop, and a 5-10% decrease in runtime ofbulk_set_node
./bench_get_node
: This benchmarks the reading of vectors and the pushing of nodes. I have noticed a 10-40% decrease in the runtime of this benchmark./bench_pos
: This benchmarks the pushing of vectors. I have noticed a 5-10% decrease in its runtime.