Performance: should changing from if conditions to calling different functions be preferred?
Posted: Mon Jun 01, 2020 1:38 pm
Suppose I have a code in the `draw`:
In the keypress handler which then sets self:paused to true, there are two different ways one could do:
1. Add this if statement into the draw() call and check every render request if we are paused and decided what to draw based on that.
2. In the pause handler change the draw function of `self` to draw only pause stuff, and when the unpause, change it only to call `draw_game`.
I suppose we perform more useless operations checking every frame whether we are paused which we can simply avoid by directing the code what to draw exactly. This should increase performance. I couldn't find any Lua or LuaJIT documentation about this, unfortunately.
Code: Select all
function Running:draw()
if self.paused then
self:draw_pause()
self:draw_hud()
return
end
self:draw_game()
end
1. Add this if statement into the draw() call and check every render request if we are paused and decided what to draw based on that.
2. In the pause handler change the draw function of `self` to draw only pause stuff, and when the unpause, change it only to call `draw_game`.
I suppose we perform more useless operations checking every frame whether we are paused which we can simply avoid by directing the code what to draw exactly. This should increase performance. I couldn't find any Lua or LuaJIT documentation about this, unfortunately.