Sphinx.
![]() |
If you're concerned about the performance of your script, check out this page:
http://lua-users.org/wiki/OptimisationCodingTips ..Good stuff in there. Please add your own findings to this thread, and feel free to post optimization problems ![]() |
|||||
Posted: June 16, 2010 3:30 am | ||||||
Vladimir Golovin
Administrator |
That's a good argument in favor of local which I used to dislike for aesthetic reasons. |
|||||
Posted: June 16, 2010 5:05 am | ||||||
Sphinx.
![]() |
Indeed! Also moving functions inside a main function (e.g. get_sample) seem to have impact. Dunno why that is, but its probably something related (less indexing or something)
Another thing I noticed is that the evaluation of conditionals with else parts can be slower than simply preinitializing the variable with the else part: j = 0 if (i == true) then j = 1 end instead of if (i == true) then j = 1 else j = 0 end but of course it depends on the actual case: if the else part is a heavy piece of code performancewise, its not worth it. |
|||||
Posted: June 16, 2010 5:40 am | ||||||
Darrell Plank |
In assembler (well, at least the ancient 8086/88 assembler I used to write in), jumping takes longer than straight line code. If you write (the assembler equivalent of)
j = 0 if (i == true) then j = 1 end then you are making no jumps if i== true and even though you're setting j twice, that's way trumped by not making a jump and therefore faster. In the other example you're always making a jump. This performance thing had to do with the pipeline in the old xx86 processors and unless LUA compiles directly to assembly (dunno, but I doubt it), then this isn't the direct reason but it may still be that in LUA jumps are expensive for whatever reason. Darrell |
|||||
Posted: July 1, 2010 12:40 am | ||||||
Sphinx.
![]() |
This page show some interesting tests - I learned a few new tricks there
![]() http://trac.caspring.org/wiki/LuaPerformance |
|||||
Posted: July 10, 2010 7:31 am | ||||||
Totte
![]() |
Very good info Sphinx!
- I never expected the Spanish inquisition |
|||||
Posted: July 10, 2010 11:23 am | ||||||
Sphinx.
![]() |
I started a new wiki page on the subject. Check it out and feel free to add stuff to it
![]() Edit: The article covers very basic scripting concepts, so its a good read for scripting beginners ![]() |
|||||
Posted: November 15, 2010 5:55 am | ||||||
Vladimir Golovin
Administrator |
Just wanted to say that this is an excellent article! |
|||||
Posted: November 24, 2010 2:16 pm | ||||||
Sphinx.
![]() |
Thanks Vlad, I will be completing it soon - I'll probably split it up, so the examples are on a dedicated page.
If Egret or one of the programmers could take a quick look at it when they have a minute or two, that would be great - I'm not 100% sure about all the conclusions / assumptions I make. Btw have you considered LuaJIT? I recall there was some problem with terminating endless loops, but perhaps you could make it optional (in the script settings add some sort of "Optimized (Unsafe)" option) |
|||||
Posted: November 25, 2010 2:18 am | ||||||
Sphinx.
![]() |
Alright, the Scripting Tips and Tricks article is complete (for now).
It would be great with some feedback on it, specially regarding clarity: if certain parts need additional explanations etc, let me know. Also if there are common operations you'd like to see covered, let me know. |
|||||
Posted: December 6, 2010 5:24 am | ||||||
James |
If i have 4 black and white gradients i noticed replacing them with scripted versions makes the render time go from 5.4 to about 10+ for some reason.
For the gradient though it is just - function prepare() end; function get_sample(x, y) return x, x, x, 1 end; So i am wondering if there is even a good way to optimize that type of code since it is so simple. Maybe the default nodes are just a great deal more faster than Lua, since the default node has other controls as part of it though i was originally guessing the Lua version would be more optimized. |
|||||
Posted: May 13, 2011 1:44 pm | ||||||
Sphinx.
![]() |
I did some experiments regarding just that. You can read about it here: http://www.filterforge.com/wiki/index..._script.22 Indeed there is a way to "optimize" that type of very simple scripts: don't script ![]() The rule of thumb is simple: if you can easily construct the script equivalent just using a few native FF components, then its a better choice. |
|||||
Posted: May 17, 2011 1:44 am | ||||||
James |
Thanks, I was expecting that would be the answer.
Hopefully in the future this might change though, it would be great if the lua scripting could be made a bit faster so things like the simple gradient code i posted would rival or be faster than the standard node. ![]() I just had a interesting idea - http://www.filterforge.com/forum/read...ssage93321 |
|||||
Posted: May 17, 2011 10:19 am | ||||||
inujima
![]() |
||||||
Posted: May 17, 2012 2:02 pm | ||||||
Sphinx.
![]() |
Good one Inujima!
Importance of localization:
And this one was new to me (initialization of table entries):
|
|||||
Posted: May 18, 2012 2:55 am |
Filter Forge has a thriving, vibrant, knowledgeable user community. Feel free to join us and have fun!
33,712 Registered Users
+19 new in 30 days!
153,534 Posts
+32 new in 30 days!
15,348 Topics
+73 new in year!
19 unregistered users.