-
Notifications
You must be signed in to change notification settings - Fork 123
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
optimize mvps_push_or_pull #662
Changes from 1 commit
00359e7
ba9b250
bc9ed16
a7c8146
5be0ee9
43a568d
22eae4b
068da0c
4c27c65
79214b5
ab2df3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,8 +70,8 @@ function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky) | |
local nodes = {} | ||
local pos_set = {} | ||
local frontiers = mesecon.fifo_queue.new() | ||
--local vector_equals = vector.equals | ||
frontiers:add(vector.new(pos)) | ||
-- micro-optimization: lift local definitions out of loop | ||
local nodedef | ||
local np_hash | ||
local nn | ||
|
@@ -100,7 +100,7 @@ function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky) | |
-- If adjacent node is sticky block and connects add that | ||
-- position | ||
for _, r in ipairs(mesecon.rules.alldirs) do | ||
local adjpos = vector.add(np, r) | ||
adjpos = vector.add(np, r) | ||
-- optimization: don't check blocks that are already part of the stack | ||
if not pos_set[minetest.hash_node_position(adjpos)] then | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What’s about r==dir? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't fully understand, do you mean i should add an additional optimization to skip this code when r==dir, since that block will already have been added to the queue? i guess that's a missed optimization then, yeah. do you want me to add it? |
||
adjnode = minetest.get_node(adjpos) | ||
|
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.
It would be new to me that lifting local variable declarations out of their scope is cheaper. May I ask where you read about this?
(Also, imho it hinders code quality.)
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.
this is based on personal testing, and is likely not worth it.
unless LuaJIT automatically does this, a local variable would have to have space for it allocated, which necessarily takes time.