About performance optimization
by Benjamin L. Grauer · in Torque Game Builder · 07/08/2007 (3:47 am) · 6 replies
Hi.
The game I'm making is doing well, and most of the gameplay code is almost over, but it begins to be really big and there's too much FPS drops. It need some optimization.
But, I don't really know what functions I need to tone down and the one I don't need to worry about. So I have some questions :
1) I heard that calling functions using 0ms schedules may let the processes take their time, so maybe it's a good idea to make a lot off instant schedules everywhere (especially in onupdatescene I suppose), but I'm not really sure, because I might maybe want to have the less schedules as possible (as I saw this statement somewhere else)...
2) Instead of using one big .cs script file, I use a lot of little ones that calls each other when needed, it's maybe nothing, or maybe it has some impact on speed.
3) I already manage my imagemaps by preloading-unloading them adequately for each level. But I don't really know the amount of imagemaps I must limit myself for each level. Does someone know a way to know the amount of ram and vram used by torque with precision ?
4) Is using linked imagemaps for animation is better than single big pictures ?
5) For sounds I use only streamed ogg for every SFX and BGM. Is non-streamed or wav sounds are better for performances ? Does openAL take a lot of processing so I must use it with parsimony ?
Also, there's maybe other things I need to pay attention that I overlooked.
Thanks for the help :)
PS : I don't own a pro version so c++ optimization is impossible :[
The game I'm making is doing well, and most of the gameplay code is almost over, but it begins to be really big and there's too much FPS drops. It need some optimization.
But, I don't really know what functions I need to tone down and the one I don't need to worry about. So I have some questions :
1) I heard that calling functions using 0ms schedules may let the processes take their time, so maybe it's a good idea to make a lot off instant schedules everywhere (especially in onupdatescene I suppose), but I'm not really sure, because I might maybe want to have the less schedules as possible (as I saw this statement somewhere else)...
2) Instead of using one big .cs script file, I use a lot of little ones that calls each other when needed, it's maybe nothing, or maybe it has some impact on speed.
3) I already manage my imagemaps by preloading-unloading them adequately for each level. But I don't really know the amount of imagemaps I must limit myself for each level. Does someone know a way to know the amount of ram and vram used by torque with precision ?
4) Is using linked imagemaps for animation is better than single big pictures ?
5) For sounds I use only streamed ogg for every SFX and BGM. Is non-streamed or wav sounds are better for performances ? Does openAL take a lot of processing so I must use it with parsimony ?
Also, there's maybe other things I need to pay attention that I overlooked.
Thanks for the help :)
PS : I don't own a pro version so c++ optimization is impossible :[
#2
How much does transparent static sprites (alpha blending is 0) affect performance? I have about 3 in my level so far, they are just used as special effect things- one for health damage, one for shield damage, and one for lighting effects.
07/10/2007 (7:20 am)
Yeah, I'm going to have to optimize my project soon too. I think the fact that I'm using 25ms timers for the player and for all the enemies is really killing me.How much does transparent static sprites (alpha blending is 0) affect performance? I have about 3 in my level so far, they are just used as special effect things- one for health damage, one for shield damage, and one for lighting effects.
#3
07/14/2007 (5:30 pm)
Thanks a lot Stephen for the tip ^^
#4
May I also ask a question about the optimization?
In C++, ++variable executes faster than variable++. Is it also true for TorqueScript? And do you plan to add variable types to remove lots of string<->number conversions?
07/14/2007 (6:13 pm)
Stephen:May I also ask a question about the optimization?
In C++, ++variable executes faster than variable++. Is it also true for TorqueScript? And do you plan to add variable types to remove lots of string<->number conversions?
#5
07/15/2007 (2:43 am)
I think the prefixed ++ is not supported in Torquescript ;)
#6
No, there is no plan to add fully typed data to TorqueScript, although there are some mechanisms that either check the underlying expected type of a variable before performing operations, or limit operations to a "type" of data, such as object, or floating point number, or int.
07/15/2007 (8:02 am)
Michael is correct, in TorqueScript there is no pre-increment only post increment.No, there is no plan to add fully typed data to TorqueScript, although there are some mechanisms that either check the underlying expected type of a variable before performing operations, or limit operations to a "type" of data, such as object, or floating point number, or int.
Torque 3D Owner Stephen Zepp
Yes, in some ways this means "hey, you might have to violate some 'good programming practices', especially in regards to readability", but very deep function call stacks and rapid firing of function calls does have overhead that can be removed with some knowledge of alternate implementation.
For example, something like:
function getCurrentList() { // return the list return "0 1 2 3 4 5 6 7 8 ..99"; } function getCurrentListCount() { // code here that figures out the number of elements in the list return %count; } function myCode() { .... // processing a string based list of values for (%x =1; %x <getCurrentListCount();%x++) { %listMember = getWord(getCurrentList(), %x); } }as compared to
function myCode() { ... // processing a string based list of values %listCount = getCurrentListCount(); %list = getCurrentList(); for (%x=1; %x < %listCount; %x++) { %listMember = getWord(%list, %x);The second example removes 99 useless calls to both the getCurrentList() and getCurrentListCount() calls, since the data itself is static during this execution stack--nothing within our loop changes either the value of the list itself, or the count of the list, so it's better to grab those values once, then use them 100 times, instead of grabbing those values 100 times, and using them once each.
This technique for optimization needs to be applied carefully--you may actually be changing values for example, so it's important to know exactly what's going on before you make optimization changes.