playMaker

Author Topic: Performance Optimizations Help  (Read 6967 times)

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Performance Optimizations Help
« on: May 01, 2011, 08:54:16 AM »
So I'm at the end of my project, and on all of the iOS devices except the iPad2 I'm getting some major audio stuttering during CPU spikes, and after doing some deep profiling I can put it all down to PlayMaker unfortunately.  Obviously being at the end of the project I can't exactly go back and re-wrote all my logic in straight code, so I was wondering if anyone had any suggestions on performance tuning?

The biggest issue is the Audio, as sound effects always trigger when a whole bunch of processing has to happen:
E.G. player gets hit, physics checks, change states on multiple objects, lots of state exits and entries.


jasonlee

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Performance Optimizations Help
« Reply #1 on: May 01, 2011, 11:15:09 AM »
1. Are you using lots of actions in state? Try make custom action to combine the logic?

2. Try using object pool if you haven't. Depends on type of project, object pool could dramatically improve performance

Not an expert myself, just some thoughts.

IPete2

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Performance Optimizations Help
« Reply #2 on: May 01, 2011, 06:00:45 PM »
Hi,

OK this all may seem obvious, but we could do with a bit more info, if we are to help.For example, it may help Alex better identify any significant issues if you can elaborate on what you mean by 'deep profiling'.

With audio, are you using compressed audio?, are you decompressing on load, what type of audio is it, mono, stereo, 3D? 

You are not instantiating any objects at the time of the stuttering are you? Have you checked how much memory you are using on the lower devices?  Any memory warnings in xCode?  Did you optimise all your textures?  What size are your textures?  Do you have mip mapping turned on?  how many textures are you using?  How many materials are there? What draw count are you up to?  Which version of Unity are you using 1.7? 3.x? iPhone normal/Pro?

A quick question, how come you got to the end of you project before you noticed the stuttering, this is not intended to be rude, just wondering if something you did or added towards the end has inadvertently affected the project adversely?

How many objects are you talking about? particle effects? how many sounds are you trying to play?  Do they have any effects or filters on them?

That should give us something to optimise, maybe! :)

IPete2.

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Re: Performance Optimizations Help
« Reply #3 on: May 01, 2011, 07:42:46 PM »
@IPete2 - Deep Profiling is exactly that, deep profiling using the Unity profiler.  If you need more info check it out here
Code: [Select]
http://unity3d.com/support/documentation/Manual/Profiler.html.  I'm using uncompressed audio for the quick sound effects, and I've tried various combinations of compressed and uncompressed with streaming, compressed and decompressed in memory, and all end up with the same issues of stuttering.

I've already implemented my own object pool system, and instantiating all objects on loading the game so there is no memory allocation going on, however I believe enabling and disabling the FSM's is having some serious impact.  I have a lot of FSM's in the scene at any one time.

I'm unable to right now but will post a screenshot of one of the deep profiled spikes that is causing the issue tonight.  It is only happening at these points.

And the reason I got to the end of the project and hadn't noticed, was that I was usually testing in editor and not on the device, and it only seemed to start happening on the devices once I started using Unity 3.3 where they made a bunch of changes to the Audio "performance", which I'm not too happy about.  I will note that it is a CPU speed issue as it is worst on the 3GS, less noticeable on the iPad, and doesn't exist on the iPad2.

Murcho

  • 1.2 Beta
  • Junior Playmaker
  • *
  • Posts: 54
Re: Performance Optimizations Help
« Reply #4 on: May 05, 2011, 01:58:05 AM »
So I finally got to the profiling, and even though I have an object pool managing everything and I'm not actually creating or destroying any objects, it is the Garbage Collector kicking in that is causing these major hiccups in performance, and they are happening very frequently, to the point that I think PlayMaker is calling it internally because it is coming up in the call graph under the profiler.

I've attached a screen shot of the profiler expanded down to the call that is taking 46.3% of the frame time (GC.Collect) and if you look above in the graph it takes around the same frame time on each of those spikes.

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Performance Optimizations Help
« Reply #5 on: May 05, 2011, 06:07:09 AM »
Wow...

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Performance Optimizations Help
« Reply #6 on: May 05, 2011, 08:52:07 AM »
Quick update. I sent Murcho a build that fixed this issue. He's now seeing a smooth 60 fps on iPad 1 :)

Fix will be in the next update...

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Performance Optimizations Help
« Reply #7 on: May 05, 2011, 03:59:00 PM »
Quick update. I sent Murcho a build that fixed this issue. He's now seeing a smooth 60 fps on iPad 1 :)

Fix will be in the next update...

Great research and find by Murcho, and thanks for fixing it so quickly Alex. Looking forward to the update, I'm sure that will be happy news to all users.

IPete2

  • Playmaker Newbie
  • *
  • Posts: 23
Re: Performance Optimizations Help
« Reply #8 on: May 05, 2011, 04:28:19 PM »
Agreed,

Great find Murcho - and thanks for taking the time to post and thanks to Alex for sorting it out so quickly.  Great support!

IPete2.

jasonlee

  • Playmaker Newbie
  • *
  • Posts: 12
Re: Performance Optimizations Help
« Reply #9 on: May 06, 2011, 12:30:29 PM »
Quick update. I sent Murcho a build that fixed this issue. He's now seeing a smooth 60 fps on iPad 1 :)

Fix will be in the next update...

Curious about what's the magic? Mind reveals your secret here? :)

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Performance Optimizations Help
« Reply #10 on: May 08, 2011, 03:40:18 AM »
Murcho's sleuthing made it easy to fix really. Didn't realize that adding/removing delegates would trigger GC calls, and this was happening even if there was no PlayMakerGUI in the scene. So just had to optimize how that was being handled...