This is for all those for have been looking for techniques to improve their coding style, and all those who want to learn.
This is a part of LuaGems, more precisely chapter two.
Guess it might be useful to you. I was, to me.
Link: Lua Performance Tips, By Roberto Ierusamlischy.
Lua Performance Tips
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Lua Performance Tips
This is another good page to read: http://trac.caspring.org/wiki/LuaPerformance
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Lua Performance Tips
I only looked through the first one there quickly, and was really surprised that
is faster than
Is this true for love functions as well? Should you like do
and so on? I already do that with some functions, but only when I want to change them.
Code: Select all
local sin = math.sin
many times sin(x)
Code: Select all
many times math.sin(x)
Code: Select all
local print = love.graphics.print
Last edited by T-Bone on Thu Aug 11, 2011 1:22 pm, edited 1 time in total.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Lua Performance Tips
Of course, it is... Just assume that love functions are packed in a global table. Assigning them to local function make them run faster.T-Bone wrote:Is this true for love functions as well?
Anyway, I am pretty sure that this is unecessary, cause Löve engine is fast enough. That would be superfluous...
@Taehl: Thanks for that link!
- Taehl
- Dreaming in associative arrays
- Posts: 1025
- Joined: Mon Jan 11, 2010 5:07 am
- Location: CA, USA
- Contact:
Re: Lua Performance Tips
T-Bone, the basic idea is that Lua can look up local variables (and functions are variables in Lua) faster than it can global variables.
Earliest Love2D supporter who can't Love anymore. Let me disable pixel shaders if I don't use them, dammit!
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Lenovo Thinkpad X60 Tablet, built like a tank. But not fancy enough for Love2D 0.10.0+.
Re: Lua Performance Tips
Code: Select all
local print = love.graphics.print()
Code: Select all
local print = love.graphics.print
Re: Lua Performance Tips
I understand. It's faster but not so fast that you have to care unless you're doing lots of calls to the same function in one specific place.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: Lua Performance Tips
Yep, for example:T-Bone wrote:I understand. It's faster but not so fast that you have to care unless you're doing lots of calls to the same function in one specific place.
Code: Select all
for i = 1, 100 do
love.graphics.print(i, i*10, 10)
end
Code: Select all
local print = love.graphics.print
for i = 1, 100 do
print(i, i*10, 10)
end
Re: Lua Performance Tips
The speed difference would still not be noticeable.
What the author writes on the first page is the most important part of the whole article:
Also note that you will probably get better results if you try to reduce the overall complexity and optimize your algorithms (save intermediate results, preprocess data, divide and conquer, math, that sort of stuff) before you go on to micro-optimizations like the ones mentioned in the article.
And above all:
What the author writes on the first page is the most important part of the whole article:
LuaProfiler is great for that.We should not try to optimize software without proper measurements.
Also note that you will probably get better results if you try to reduce the overall complexity and optimize your algorithms (save intermediate results, preprocess data, divide and conquer, math, that sort of stuff) before you go on to micro-optimizations like the ones mentioned in the article.
And above all:
Bruce Whiteside wrote:Make it work before you make it work fast.
Who is online
Users browsing this forum: No registered users and 4 guests