1. Thread much slower then non thread. 2. Thread slower on much faster hardware
Posted: Sun Jan 22, 2023 5:43 pm
H!
I'm working on a old MacBook Air 2014, and sometimes I test the 'game' on the iMac M1.
And it was much slower.
Then I did bring the code down to a simple test case that everyone can run, and see the problem.
But I can fix it to not use threads.
The facts are:
- Love 11.4
- MacBook Air 2014 = elapsed time: 0.11
- Imac M1 = elapsed time: 1.45 !
When I don't use the Thread function and copy/past the pathfinding.lua code inside main.lua
- MacBook Air 2014 = elapsed time: 0.03
- Imac M1 = elapsed time: 0.01 !
Conclusion for me at this point:
- Never use threads for pathfinding / alias big tables, they can be a bottleneck.
- Maybe for small tables they can be use full for non important things like background stuff that not really needed.
But maybe it is a bug in SDL2/love2d?
main.lua
pathfinding.lua
Greetings,
GCMartijn
I'm working on a old MacBook Air 2014, and sometimes I test the 'game' on the iMac M1.
And it was much slower.
Then I did bring the code down to a simple test case that everyone can run, and see the problem.
But I can fix it to not use threads.
The facts are:
- Love 11.4
- MacBook Air 2014 = elapsed time: 0.11
- Imac M1 = elapsed time: 1.45 !
When I don't use the Thread function and copy/past the pathfinding.lua code inside main.lua
- MacBook Air 2014 = elapsed time: 0.03
- Imac M1 = elapsed time: 0.01 !
Conclusion for me at this point:
- Never use threads for pathfinding / alias big tables, they can be a bottleneck.
- Maybe for small tables they can be use full for non important things like background stuff that not really needed.
But maybe it is a bug in SDL2/love2d?
main.lua
Code: Select all
function love.load()
pathfinding = love.thread.newThread("pathfinding.lua")
pathfinding:start()
end
function love.update(dt)
local pathFindingResult = love.thread.getChannel("follow_path"):pop()
if pathFindingResult then
print(1)
end
end
Code: Select all
local x1, y1, x2, y2 = 0, 0, 480, 180
local collisionRectsTable = {}
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
table.insert(
collisionRectsTable,
{
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4},
{a = 1, b = 2, c = 3, d = 4}
}
)
t = 1
local function isPointInCollision(x, y)
for _, collisionRects in pairs(collisionRectsTable) do
for _, rect in pairs(collisionRects) do
t = t + 1
end
end
return false
end
local x = os.clock()
local map = {}
for y = y1, y2 do
map[y] = {}
for x = x1, x2 do
if isPointInCollision(x, y) then
map[y][x] = 1
else
map[y][x] = 0
end
end
end
print(string.format("elapsed time: %.2f\n", os.clock() - x))
print(t)
love.thread.getChannel("follow_path"):push({bla = 1})
Greetings,
GCMartijn