Profile and optimize script code?
by Blake Drolson · in Torque Game Builder · 08/21/2010 (7:16 am) · 6 replies
Hi there,
Are there any tools or methods or even tricks that other devs use to profile their script code? I know that I can run the profiler on the main engine, but if a lot of my game logic is executing in the scripts, will the C++ profiler tell me what scripts are taking different time slices??
I know I might need to move some script code into the C++ engine for speed, but I am wondering how I zero in on what is taking the time to execute besides coder's intuition.
Are there any tools or methods or even tricks that other devs use to profile their script code? I know that I can run the profiler on the main engine, but if a lot of my game logic is executing in the scripts, will the C++ profiler tell me what scripts are taking different time slices??
I know I might need to move some script code into the C++ engine for speed, but I am wondering how I zero in on what is taking the time to execute besides coder's intuition.
#2
You still need to write your own profiling. I've done something as simple as keeping the cumulative times in global variables mapped by name:
Like Alain Labrie, I base what to wrap on past C++ optimization experience. After setting up a few regions, I can then at least compare which of those regions are the slowest. I may have totally missed the slowest section, but it's a start.
08/21/2010 (4:06 pm)
If you follow the steps here, you can get a high resolution timer that works within a single function call. You still need to write your own profiling. I've done something as simple as keeping the cumulative times in global variables mapped by name:
$PROFILE["AI_THINK"] += %thinkTime;
Like Alain Labrie, I base what to wrap on past C++ optimization experience. After setting up a few regions, I can then at least compare which of those regions are the slowest. I may have totally missed the slowest section, but it's a start.
#3
08/24/2010 (2:56 am)
Guys thanks for the tips, William you rock! You are so helpful!
#4
www.garagegames.com/community/forums/viewthread/126074
05/24/2011 (7:47 pm)
I have some follow up profiler questions here, if anyone wants to chime in...www.garagegames.com/community/forums/viewthread/126074
#5
Make sure you turn off all collision detection for things that don't need it. If you've got a jillion sprites flying around onscreen it won't help much that they don't have a collision RESPONSE set up for them hitting each other -- the thing that kills the framerate is that they're all TESTING to see if they're hitting each other.
So yeah, if it doesn't need it at all, turn it off. If a large group of things need collision testing but not against each other, be sure to set up your collision groups appropriately so they don't test against each other, etc.
Fixing both of these boosted the number of "things" I could push around onscreen before slowdown by a factor of 10x or more, if I remember correctly.
No idea what your crazyness that you're attempting is really, but figured I'd throw that out there.
05/29/2011 (8:41 am)
Here's a random "gotcha"-style tip that messed with me pretty badly once when adding lots of 'crazyness' to a game...Make sure you turn off all collision detection for things that don't need it. If you've got a jillion sprites flying around onscreen it won't help much that they don't have a collision RESPONSE set up for them hitting each other -- the thing that kills the framerate is that they're all TESTING to see if they're hitting each other.
So yeah, if it doesn't need it at all, turn it off. If a large group of things need collision testing but not against each other, be sure to set up your collision groups appropriately so they don't test against each other, etc.
Fixing both of these boosted the number of "things" I could push around onscreen before slowdown by a factor of 10x or more, if I remember correctly.
No idea what your crazyness that you're attempting is really, but figured I'd throw that out there.
#6
One thing I found out is to watch out for the schedule calls, I was calling schedule for things that were animating by code, or things being emitted (the crazyness). Thing is when the frame rate got low, these things were then being called multiple times for one frame, making more work to calculate for that frame, which would make the frame take longer, which would make the next frame have even more schedule calls to handle etc. Once the frame rate was low enough it would never recover.
What I am doing is for things like animation by code, is to replace the schedule calls with a update call during the scene tick, so that these things only animate once per frame saving time when the frame rate is low.
I have also identified a few key spots where my code is getting tied up and will be doing what I can to optimize them, so I can keep my crazy effects as much as possible.
05/29/2011 (12:22 pm)
Yeah thats a good tip, is collision detection turned off by default when you create a sprite?One thing I found out is to watch out for the schedule calls, I was calling schedule for things that were animating by code, or things being emitted (the crazyness). Thing is when the frame rate got low, these things were then being called multiple times for one frame, making more work to calculate for that frame, which would make the frame take longer, which would make the next frame have even more schedule calls to handle etc. Once the frame rate was low enough it would never recover.
What I am doing is for things like animation by code, is to replace the schedule calls with a update call during the scene tick, so that these things only animate once per frame saving time when the frame rate is low.
I have also identified a few key spots where my code is getting tied up and will be doing what I can to optimize them, so I can keep my crazy effects as much as possible.
Torque Owner Alain Labrie
Ware-Wolf Games
I mainly rely on past c++ optimizing experience. i.e. Code candidates for optimization are: multiple memory allocations, heavy processing loops,and math functions (LUT are your friend):-)