Question

Lately I have been doing some performance analysis on instruments for an app. This is what I noticed:

pic1 pic2

Namely the UIButton frame setting is very slow.

To rule out the probability that it is caused by type casting (from int to CGFloat), I have tried the following:

pic3

I have also tried:

pic4

Nope, not much help either.

Last but not least I have made sure it is not caused by CGRectMake:

pic5

The function has been called roughly 650-670 times, which makes each frame setting call roughly 0.173ms? Does that sound right? How could I improve the performance?

Was it helpful?

Solution

Hmm... I'm not 100% sure but you're using button type UIButtonTypeDetailDisclosure which has a fixed size.

Try just setting the centre of it instead of the frame.

myDetailButton.center = CGPointMake(12, 12);

instead of ...

myDetailButton.frame = CGRectMake(0, 0, 23, 23);

Also the f is not required and IIRC it actually can take more memory than necessary when used. Just use 23 or 23.0 instead of 23.0f. I'll have to find a reference for this though.

EDIT

Having said that I just saw your timing stats at the bottom of the question.

The percentages you are seeing here are relative. 0.173ms is almost no time at all.

You might get a better performance improvement by not running the function so many times. You're running it 700 times. Thats a LOT! Do you really need to run it that many times. You can't even fit that many buttons onto the screen at once.

Maybe you need to dequeue them instead? You're using an MKMapView after all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top