Shark newbie needs help with perf-opt
Shark newbie needs help with perf-opt
- Subject: Shark newbie needs help with perf-opt
- From: Randall Meadows <email@hidden>
- Date: Sun, 13 Sep 2009 20:24:11 -0600
I'm trying to optimize an iPhone app. I have dozens of objects (as
many as 60 at a time) moving around the screen at once. Under certain
conditions, these objects will collide, and during these collisions,
the rest of the objects (the ones not involved in the collisions) slow
down noticeably. I had assumed it was the collision detection code
that was causing this problem; I still think so, but the results I'm
seeing in Shark beg to differ. I have to believe that it's a matter
of interpretation of the Shark data, and I'm hoping someone can set me
straight.
The objects are moved in as NSTimer callback; after all the objects
are moved on screen, collision detection is done, via a nested loop
involving all the already-collided objects against all the rest of the
objects. When I run an instance of this behavior in Shark, it tells
me that 16.9% of the time is spent in object movement, while only 5.0%
of the time is spent detecting collisions. The reason I don't think
this is correct is because the object movement degrades noticeably in
direct proportion to the amount of collisions currently in progress.
When the maximum number of objects are moving absent any collisions,
the movement is fluid; only while collisions are occurring does the
movement degrade (objects involved in collisions are currently only
being drawn at a different size (via the frame property being adjusted).
So I turned my attention to the movement code. The objects are
UIViews, whose -drawRect currently consists of only setting a color
and drawing a circle (and takes 8.5% of the CPU time). My original
code for this consisted of explicit Core Animation, um, animations,
which caused other problems with collision detection. So I changed
the movement code to manually calculate where each object should be at
a given time, and simply set its center property to move it. Of the
16.9% of the time spent in my move method, more than half of that time
(9.3%) is spent in CALayer -setPosition:. I got rid of explicit CA
animations, but I guess I'm stuck with implicit ones? Is is possible
to disable these on iPhone? I don't really care to have *any*
animation done during the move method, as I'm setting the absolute
position of the objects where they need to be when they need to be
there, so I think I want to get rid of the implicit CA stuff--am I
right?
I think the reason I'm seeing so much activity in the move method is
because that's happening constantly during the run of the program,
while the collision detection code happens only sporadically, but
clumps enough to slow down the movement code. Reasonable? Am I off
my rocker? Am I misinterpreting the Shark data?
Any other optimization tips?
I'm continuing to tinker with stuff, but while working on that I
wanted to post this before I got too far down the road/into the weeds.
Thanks.
randy
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden